从批处理文件设置VS2010环境变量? [英] Setting a VS2010 environment variable from a batch file?

查看:73
本文介绍了从批处理文件设置VS2010环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用批处理文件来定义一些将在程序中使用的变量.我希望批处理文件更改环境变量并在我的代码中使用它,但是它现在正在工作-宏没有更改.

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.

更具体明确:

  1. 我有一个程序可以创建DLL并设置其版本

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

在项目的常规设置中,我创建了一个新的宏(公共属性"->用户宏"): TEST_VER = 5

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

现在我想添加一个批处理文件,该文件将在pre-build命令中运行并更改TESTER的值

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.

但是无法识别.仍然使用5作为值

BUT it doesn't recognize it. and still uses 5 as the value

我虽然在做:该项目的特点->资源->一般并添加:TEST_VER = $(TEST_VER)仍然没用

I though doing : propeties of the project - > resourcses ->general and add : TEST_VER=$(TEST_VER) and still didn't work

有办法吗?

谢谢!

推荐答案

Visual Studio启动程序时,它将在新的子进程中运行该程序.在这种情况下,这是一个新的CMD.EXE,即命令提示符外壳.在子流程(子流程)中对环境所做的更改对父流程没有影响.Visual Studio有自己的一组环境变量,它在启动时会继承.您的批处理文件无法更改这些值.您无法按照自己的方式做自己想做的事.

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.

这篇关于从批处理文件设置VS2010环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆