visual-studio 如何将环境变量添加到 VS 解决方案 (.sln)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/634466/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add environmental variable to VS solution (.sln )
提问by user68416
I need to have my own environmental variable (like $(VsInstallDir) ) for all projects in solution. How can i define it in my solution ?
我需要为解决方案中的所有项目拥有自己的环境变量(如 $(VsInstallDir) )。我如何在我的解决方案中定义它?
I'm using VS2008, C++ solution
我正在使用 VS2008,C++ 解决方案
采纳答案by Dani van der Meer
I had a similar problem and consequent question. Take a look at the answers there. The short answer is: use property sheets.
我有一个类似的问题和随之而来的问题。看看那里的答案。简短的回答是:使用属性表。
For example:
例如:
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioPropertySheet
    ProjectType="Visual C++"
    Version="8.00"
    Name="MyIncludes"
    >
    <UserMacro
        Name="BoostInclude"
        Value="C:\Program Files\boost\boost_1_35_0"
        PerformEnvironmentSet="true"
    />
</VisualStudioPropertySheet>
回答by Chris Lawlor
You could create a project (dll) which simply held all of your environment varaibles; call it solution_env.dll or something. All of the other projects in the solution would have to reference that dll.
您可以创建一个项目 (dll),它只包含您所有的环境变量;称之为 solution_env.dll 或其他东西。解决方案中的所有其他项目都必须引用该 dll。
I suspect that there are other, better ways to accomplish what you are trying to do, but then that depends on what you are actually trying to do. What I mean is, you have some goal, and you've already decided that the solution to your goal is to have a solution-wide environment variable(s), so you've asked how to do that. It may be more beneficial to ask if there are other ways to accomplish what you are really trying to do.
我怀疑还有其他更好的方法可以完成您正在尝试做的事情,但这取决于您实际尝试做的事情。我的意思是,您有一些目标,并且您已经决定目标的解决方案是拥有一个解决方案范围的环境变量,所以您已经询问了如何做到这一点。询问是否有其他方法可以完成您真正想做的事情可能更有益。

