问题
I'm using a batch file to define some variables that will be used in my program. I want the batch file to change the environment variable and use it in my code , but it's just now working - the macro is not being changed.
to be more specific and clear :
I have a program that creates a DLL and sets it's version
In the common setting of the project - I created a new macro (Common properties->User macros) :
TEST_VER = 5
now I want to add a batch file , that will run in the pre-build command and change the value of TESTER
I wrote this in the batch file:
set TEST_VER=9
and used the path of the batch in the pre-build.
BUT it doesn't recognize it. and still uses 5 as the value
I though doing : propeties of the project - > resourcses ->general and add : TEST_VER=$(TEST_VER) and still didn't work
is there a way to do it??
thanks!!
回答1:
When Visual Studio starts a program, it runs that program in a new sub-process. In this case, that's a new CMD.EXE, the command prompt shell. Changes made to the environment in a sub-process, a child, have no effect on the parent. Visual Studio has its own set of environment variables which it inherited when it started. Your batch file can't change those values. You can't do what you want the way you're doing it.
来源:https://stackoverflow.com/questions/13901006/setting-a-vs2010-environment-variable-from-a-batch-file