Sergey
Sergey

Reputation: 412

altering PATH via property sheets when firing up a debugger in visual studio

I have a set of property sheets which define include and link paths for commonly used 3rd partly libraries in my c++ project. Is there a way to also define PATH in those pages for the executable to find the binaries when I fire it up in a debugger ?

Edit: I noticed that if I add the following to a property sheet (via notepad)

<PropertyGroup>
   <VCRedistPaths>c:\path\bin\$(Platform);$(VCRedistPaths)</VCRedistPaths>
</PropertyGroup>

Then I get c:\path\bin\Win32 (for instance) path appended when app is run under debugger, but the problem here is that visual studio doesn't detect my changes instantly (if I change the path in property sheet or append another property sheet with another path) and I have to restart visual studio for the changes to pickup. Anyone knows if this is possible to avoid ?

Upvotes: 6

Views: 3260

Answers (2)

Amro
Amro

Reputation: 124563

Here is an example property sheet that worked for me in VS2010:

mysheet.props

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup>
    <LocalDebuggerEnvironment>PATH=%MYLIB_ROOT%\bin;%PATH%$(LocalDebuggerEnvironment)</LocalDebuggerEnvironment>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <ClCompile>
      <AdditionalIncludeDirectories>$(MYLIB_ROOT)\include</AdditionalIncludeDirectories>
    </ClCompile>
    <Link>
      <AdditionalLibraryDirectories>$(MYLIB_ROOT)\lib</AdditionalLibraryDirectories>
      <AdditionalDependencies>mylib.lib</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

I get the idea of using LocalDebuggerEnvironment from manually setting the PATH environment variable in the project's properties:

proj_prop_env_var

This change was reflected in the *.vcxproj.user project option file, which I then replicated in my own property sheet.

HTH

Upvotes: 8

Hans Passant
Hans Passant

Reputation: 942099

Not sure what kind of property pages you are talking about. It cannot be set by a project property sheet, it is a debug setting. Project + Properties, Debugging, Environment setting. Set it to, say,

 path = c:\foo;c:\bar

and they will be merged into the system environment's value of the PATH variable.

Beware that relying on the PATH is not a good practice in general. You will need to create an installer to ensure the user's machine has the proper PATH value. A reboot is needed to ensure it takes effect. And it is easily destroyed by crummy installers that run after yours.

The better approach is use a post build event that uses xcopy /d to copy the required DLLs into $(TargetDir).

Upvotes: -1

Related Questions