Setting a VS2010 environment variable from a batch file?(从批处理文件中设置 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.
更具体和明确:
我有一个程序可以创建一个 DLL 并设置它的版本
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 环境变量?


基础教程推荐
- 常量变量在标题中不起作用 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01