Visual Studio .sln和.vcproj文件中的宏/环境变量 [英] Macros/Environment variable in .sln and .vcproj files for Visual studio

查看:183
本文介绍了Visual Studio .sln和.vcproj文件中的宏/环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个类似的问题:

a)我有一个包含多个项目的解决方案,并且我希望能够通过设置一些环境变量/宏来轻松切换项目位置. 例如,该项目可以位于 \ SolutionDir \ Dir1 \或\ SolutionDir \ Dir2 \ 因此,我想指定它应该位于\ SolutionDir \ $(Var)中,然后设置变量.

a) I have a solution which includes several projects and I want to be able easily switch project location by setting some environment variable/macro. As example this project can be located in \SolutionDir\Dir1\ or \SolutionDir\Dir2\ So, I want to specify that it should be located in \SolutionDir\$(Var) and just set the variable.

Visual Studio中是否有任何构建方法可以实现?

Is there any build in Visual Studio way to do it?

我目前仅知道两种解决方案-手动/以编程方式编辑.sln文件以查找此项目并设置正确的路径.

I know currently only two solutions - edit .sln file manual/programmatically to find this project and set correct path.

我无法在.sln文件中使用环境变量.

I wasn't able to use environment variable in .sln file.

b)我有一个包含资源(.rc和.h)文件的项目.我希望能够通过其他环境变量或宏来设置它们的位置.

b) I have a project which includes resources (.rc and .h) files. I want to be able to set their location through other environment variable or macro.

\ ProjectDir \ $(Var2)\ resource.rc之类的东西

Something like \ProjectDir\$(Var2)\resource.rc

我在属性表上发现了一些很有希望的信息,但是当我在.vcproj的File标签中使用宏时,Visual Studio不会扩展宏.

I found some promising info on property sheets, but Visual studio doesn't expand macros when I am using them in File tag in the .vcproj.

谢谢您提供解决此问题的想法.

Thank you for any ideas how to solve this problem.

关于, 维克多

推荐答案

只需在相关字段中使用环境变量:

Just use the environment variable in the relevant field:

OutputDirectory="$(MyEnvVariableName)\Bin"

一个技巧是每次更改变量时都需要重新启动Visual Studio IDE.

One trick is that you need to restart the Visual Studio IDE each time you change the variable.

有一篇有关此的MSDN文章:如何:在构建

There is an MSDN article precisely about this: How to: Use Environment Variables in a Build

这篇关于Visual Studio .sln和.vcproj文件中的宏/环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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