6

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 ?

Amro
  • 123,847
  • 25
  • 243
  • 454
Sergey
  • 403
  • 1
  • 5
  • 13

2 Answers2

8

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

Amro
  • 123,847
  • 25
  • 243
  • 454
  • Thanks, will check that. I use visual studio with intel compiler installed, and I think intel compiler installation changes the defaults for LocalDebuggerEnvironment property. – Sergey May 26 '13 at 07:26
  • 1
    I also used LocalDebuggerEnvironment in a *.props file, but with no effect. I used this to load Qt DLL's to the project. It seems, that the inheritance mechanism of the IDE here doesn't work (not a other tool, like the Qt Add-In or the intel compiler). After manually setting the enviroment with the IDE it works and saves the setting in the *.vcxproj.user file. So you can share this file, instead the *.props file. – bzs Sep 27 '13 at 07:58
  • This actually does work, but there are a few more pitfalls that may cause issues (ex. overwriting the variable in the project and not realizsing it). Here is an example of the setup that works: https://github.com/okigan/vsprops_example – okigan Jan 08 '14 at 02:10
  • 1
    A note to this: Changes to the `LocalDebuggerEnvironment` property will be activated only if you **reload the solution in Visual Studio**. Why that is, I don't know, but it seems there are some properties that are evaluated at project initialization instead of build time. – uceumern Mar 24 '17 at 10:04
-1

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

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • By property pages I mean property sheets (sorry for confusion). I know that I can't do it via visual studio interface, thus the question here since msbuild is a very powerfull system, and not everything is exposed. Your solution works, but not flexible since I have many property sheets pointing to various 3rd-party stuff, which I can drag-in/out, which point to different versions of libraries, etc/etc, and messing with that environment field gets out of control quickly, besides I want my changes automatically appear on other developers machines. – Sergey Oct 28 '12 at 14:55
  • I answered your question about the PATH environment variable. Did you ask the wrong question? – Hans Passant Oct 28 '12 at 15:12
  • Thanks for your answer, but my target goal is to make the loader pick up dependent dlls at thier original locations. Copying doesn't seem to be a good option either, since it increases the build time (sometimes quite significantly) and I don't think you can easily stack the copies from multiple property sheets. – Sergey Oct 28 '12 at 15:22