简体   繁体   中英

Debugger multiple environment variables in C++ Microsoft Visual Studio 2010

I got a very simple problem with the Visual Studio 2010 Professional C++ debugger when setting environment variables.

Described in
http://msdn.microsoft.com/en-en/library/kcw4dzyf.aspx
Paragraph "Environment (Local Windows Debugger)".

I created a standard Win32 console project. I am setting the environment in project properties → Debugger :

TEST=asdf
OTHER=qwer

And printing the environment variables in the _tmain(...):

cout << "Hello " << getenv("TEST") << endl;

I would expect an out like:

"Hello asdf"

But instead I always get:

"Hello asdf OTHER=qwer"

How to fix this?!


It seems to be a DEU version bug.

I just filed a bug report: https://connect.microsoft.com/VisualStudio/feedback/details/727324/msvs10-c-deu-debugger-environment-variables-missing-linefeed#details

Running into a similar problem feeding this property programmatically, I bumped into this github file . The separator is "&#xA;" in xml format, aka line feed. Using Environment.Newline solved the issue in dot net.

In interactive mode within the GUI, you want to click the edit button and use the rerun key to split your variables.

Best solution so far:

Considering your example:

TEST=asdf
OTHER=qwer

Edit the .vcxproj adding inside <Project> :

  <Project .... >
  ...

  <PropertyGroup Label="UserMacros">
  <TEST>asdf</TEST>
  <OTHER>qwer</OTHER>
  </PropertyGroup>

  ...
  </Project>

You can also add this on a *.vcxproj.user or a *.props file as you prefer.

Do you need to separate the environment variables with semicolons or some other kind of delimiter? It seems like TEST is getting assigned to asdf OTHER=qwer , not just asdf .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM