简体   繁体   English

如何将环境变量添加到 VS 解决方案(.sln)

[英]How to add environmental variable to VS solution (.sln )

I need to have my own environmental variable (like $(VsInstallDir) ) for all projects in solution.我需要为解决方案中的所有项目拥有自己的环境变量(如 $(VsInstallDir) )。 How can i define it in my solution?如何在我的解决方案中定义它?

I'm using VS2008, C++ solution我正在使用VS2008,C++解决方案

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>

You could create a project (dll) which simply held all of your environment varaibles;您可以创建一个项目(dll),它只包含您所有的环境变量; call it solution_env.dll or something.称它为 solution_env.dll 之类的。 All of the other projects in the solution would have to reference that 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.询问是否有其他方法可以完成您真正想做的事情可能会更有益。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM