问题
The application I need to debug expects environment variables to be set. This seems ridiculously complicated in Visual Studio 2012. I'd like to do something like:
set path=c:\foo;c:\bar;c:\windows;c:\program files\application
set port=12345
set server=hulligulli
Microsoft tells me I should just "Use standard environment variable syntax". So I expected I could just open Configuration Properties/Debugging/Environment and write
set path=c:\foo;c:\bar;c:\windows;c:\program files\application
set port=12345
set server=hulligulli
Or:
path=c:\foo;c:\bar;c:\windows;c:\program files\application
port=12345
server=hulligulli
But both variants don't work. The upper doesn't set the path at all. In the lower version Visual Studio splits the entry on each space, so the three lines above become the four lines below:
path=c:\foo;c:\bar;c:\windows;c:\program
files\application
port=12345
server=hulligulli
These two variants below prevent the split-up, but they also prevent the path to be correctly formatted. Viz. the application won't find files in the path:
path=c:\foo;c:\bar;c:\windows;"c:\program files\application"
path="c:\foo;c:\bar;c:\windows;c:\program files\application"
After working around the space-in-path-problem by copying everything to paths without spaces, I found out, that seemingly only the first line of the environment is actually used. Viz. port and server are not set.
path=c:\foo;c:\bar;c:\windows;c:\alternative_path\application
port=12345
server=hulligulli
How do I set more than one environment variable in the Visual Studio debugging environment?
Bonus question: How do I use standard path entries (with spaces) in the Visual Studio debugging environment?
回答1:
Visual Studio doesn't allow more than one environment variable to be set. It's a known bug. And Microsoft has no intention to fix it.
Someone suggested to manually edit the vcproj.user-file and replace line-breaks by & #xD; & #xA; (that's: CRLF). But that fixes only the appearance in the environment Field, not the behavior.
Setting the variables in a <PropertyGroup> in the vcxproj-file as proposed in How to set environment variables in vs2012? doesn't help either.
Workaround: set the variables at the shell and then start Visual Studio from that shell.
Update: This problem seems to be fixed in Visual Studio 2015.
来源:https://stackoverflow.com/questions/22529919/setting-c-debug-environment-in-visual-studio-2012-express