从批处理文件中设置 VS2010 环境变量?

Setting a VS2010 environment variable from a batch file?(从批处理文件中设置 VS2010 环境变量?)

本文介绍了从批处理文件中设置 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

现在我想添加一个批处理文件,它将在预构建命令中运行并更改 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 环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:从批处理文件中设置 VS2010 环境变量?

基础教程推荐