93

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

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
yesraaj
  • 46,370
  • 69
  • 194
  • 251

5 Answers5

117

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.)

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

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

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

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

PATH=%PATH%;$(TargetDir)\DLLS
CharlesB
  • 86,532
  • 28
  • 194
  • 218
Multicollinearity
  • 1,179
  • 2
  • 7
  • 3
55

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 here and manipulate the path in that one
  • You can copy the DLLs into the executable file's directory :-)
Community
  • 1
  • 1
Timo Geusch
  • 24,095
  • 5
  • 52
  • 70
  • 7
    With Visual Studio 2010, you can go in your project's property pages, and it's under "Configuration Properties -> VC++ Directories". – Kevin Doyon Jun 29 '10 at 03:34
  • 3
    @Kevin This is for building, not for running or debugging – user362515 Apr 30 '16 at 15:35
  • Bullet 1 is deprecated in VS Community 2015. "It is now available as a user property sheet that is added by default to all projects." – Richard Jessop Feb 05 '19 at 17:32
  • 2
    In VS 2019 you set this in `Project properties -> Common properties -> VC++ Directories -> Executable Directories` you can also add project property sheet and set it there and add the property sheet to all new projects. – metablaster May 25 '20 at 15:50
  • Alternatively if it doesn't work then: `Project properties -> Common properties -> Debugging -> Environment` add this `PATH=%PATH%; MY_DLL_DIR` replacing the `MY_DLL_DIR` with directory to DLL directory, note the semicolon! – metablaster May 25 '20 at 15:56
11

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.

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
sean e
  • 11,792
  • 3
  • 44
  • 56
2

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.

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.

Mr Fooz
  • 109,094
  • 6
  • 73
  • 101
1

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).

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

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

And then adding:

$(SystemRoot)\system32;$(SystemRoot);$(SystemRoot)\System32\Wbem;$(SystemRoot)\System32\WindowsPowerShell\v1.0\;$(ExecutablePath)
user27221
  • 334
  • 3
  • 16