Setting a VS2010 environment variable from a batch file?

给你一囗甜甜゛ 提交于 2021-02-15 07:42:54

问题


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 :

  1. I have a program that creates a DLL and sets it's version

  2. In the common setting of the project - I created a new macro (Common properties->User macros) : TEST_VER = 5

  3. 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

enter image description here

enter image description here

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!