visual-studio 如何在 Visual Studio 中设置路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/428085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:03:13  来源:igfitidea点击:

How do I set a path in Visual Studio?

visual-studiovisual-c++development-environment

提问by yesraaj

How do I set a path for DLL files to be searched in Visual Studio for a particular project alone?

如何为要在 Visual Studio 中单独搜索特定项目的 DLL 文件设置路径?

Now I am setting it in the environment pathvariable, but I would like better control over this.

现在我将它设置在环境path变量中,但我想更好地控制它。

采纳答案by Timo Geusch

You have a couple of options:

您有几个选择:

  • You can add the path to the DLLs to the Executable files settings under Tools > Options > Projects and Solutions > VC++ Directories (but only for building, for executing or debugging here)
  • You can add them in your global PATH environment variable
  • You can start Visual Studio using a batch file as I described hereand manipulate the path in that one
  • You can copy the DLLs into the executable file's directory :-)
  • 您可以在工具的路径添加到DLL文件的可执行文件设置>选项>项目和解决方案> VC ++目录(但仅限于建立,执行和调试这里
  • 您可以将它们添加到全局 PATH 环境变量中
  • 您可以使用我在此处描述的批处理文件启动 Visual Studio并操作该文件中的路径
  • 您可以将 DLL 复制到可执行文件的目录中 :-)

回答by Multicollinearity

Search MSDN for "How to: Set Environment Variables for Projects". (It's Project>Properties>Configuration Properties>Debugging "Environment"and "Merge Environment"properties for those who are in a rush.)

在 MSDN 中搜索“如何:为项目设置环境变量”。(对于那些匆忙的人来说,它是项目>属性>配置属性>调试“环境”“合并环境”属性。)

The syntax is NAME=VALUEand macros can be used (for example, $(OutDir)).

语法是NAME=VALUE并且可以使用宏(例如,$(OutDir))。

For example, to prepend C:\Windows\Temp to the PATH:

例如,要将 C:\Windows\Temp 添加到 PATH:

PATH=C:\WINDOWS\Temp;%PATH%

Similarly, to append $(TargetDir)\DLLS to the PATH:

类似地,要将$(TargetDir)\DLLS附加到 PATH:

PATH=%PATH%;$(TargetDir)\DLLS

回答by sean e

If you only need to add one path per configuration (debug/release), you could set the debug command working directory:

如果您只需要为每个配置(调试/发布)添加一个路径,您可以设置调试命令工作目录:

Project | Properties | Select Configuration | Configuration Properties | Debugging | Working directory

项目 | 属性 | 选择配置 | 配置属性 | 调试 | 工作目录

Repeat for each project configuration.

对每个项目配置重复。

回答by Mr Fooz

Set the PATH variable, like you're doing. If you're running the program from the IDE, you can modify environment variables by adjusting the Debugging options in the project properties.

像您一样设置 PATH 变量。如果您从 IDE 运行程序,则可以通过调整项目属性中的调试选项来修改环境变量。

If the DLLs are named such that you don't need different paths for the different configuration types, you can add the path to the system PATH variable or to Visual Studio's global one in Tools | Options.

如果 DLL 的命名方式使得您不需要针对不同的配置类型使用不同的路径,则可以将路径添加到系统 PATH 变量或 Visual Studio 的 Tools | 中的全局变量中。选项。

回答by user27221

None of the answers solved exactly my problem (the solution file I was running was trying to find xcopy to copy a dll after generation).

没有一个答案完全解决了我的问题(我正在运行的解决方案文件试图找到 xcopy 以在生成后复制 dll)。

What solved it for me was going into menu "Project -> Properties"

为我解决的是进入菜单“项目->属性”

Then in the window that opens choosing on the left pane: "Configuration Properties -> VC++ Directories

然后在打开的窗口中选择左侧窗格:“配置属性 - > VC++ 目录

On the right pane under "General" choosing "Executable Directories "

在“常规”下的右侧窗格中选择“可执行目录”

And then adding:

然后添加:

$(SystemRoot)\system32;$(SystemRoot);$(SystemRoot)\System32\Wbem;$(SystemRoot)\System32\WindowsPowerShell\v1.0\;$(ExecutablePath)