Changing PATH through property sheets when starting the debugger in visual studio

I have a set of properties that define include and link paths for commonly used 3-part libraries in my C ++ project. Is there a way to also determine the PATH on these pages for the executable to find the binaries when I run it in the debugger?

Edit : I noticed that if you add the following to the properties sheet (via notepad):

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

Then I get the path c: \ path \ bin \ Win32 (for example) when the application starts under the debugger, but the problem is that the visual studio does not detect my changes instantly (if I change the path in the sheet property or add another property page with the other way), and I have to restart visual studio to change the settings. Does anyone know if this can be avoided?

+5
source share
2 answers

Here is an example property page 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 properties:

proj_prop_env_var

This change was reflected in the project settings file *.vcxproj.user , which was then replicated in my own properties page.

NTN

+6
source

Not sure which property pages you are talking about. It cannot be set by the project properties sheet, it is a debugging parameter. Project + Properties, Debugging, Environment. Install it let's say

  path = c:\foo;c:\bar 

and they will be combined into the system environment value of the PATH variable.

Beware that using PATH is not good practice in general. You will need to create an installer to ensure that the user machine has the correct PATH value. To ensure its effectiveness, a reboot is required. And it is easily destroyed by the starch installers who work after you.

A better approach is to use the post build event, which uses xcopy / d to copy the required DLLs to $ (TargetDir).

-1
source

Source: https://habr.com/ru/post/947362/


All Articles