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

2

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 ?

Theophylline answered 28/10, 2012 at 13:28 Comment(0)
R
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

Roble answered 26/5, 2013 at 2:33 Comment(4)
Thanks, will check that. I use visual studio with intel compiler installed, and I think intel compiler installation changes the defaults for LocalDebuggerEnvironment property.Theophylline
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.Zerelda
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: github.com/okigan/vsprops_exampleProphase
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.Binetta
S
-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).

Solubility answered 28/10, 2012 at 14:43 Comment(3)
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.Theophylline
I answered your question about the PATH environment variable. Did you ask the wrong question?Solubility
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.Theophylline

© 2022 - 2024 — McMap. All rights reserved.