1
我使用environment variables in my VS2010 projects;這工作正常。如何在VS2010項目中爲變量提供默認值?
但我想有默認值,只要環境變量不存在就使用。這可能嗎?
編輯/解決:我的屬性表看起來像這樣(THIRDPARTY_ROOT可以通過在環境中設置其覆蓋):
<?xml version="1.0" encoding="utf-8"?>
<!--
* Property sheet for 3rd party libraries
*
* - The BOOST_VER variable should be set to the same value as in common.mk
* - The THIRDPARTY_ROOT variable can be overridden by an environment variable
* with the same name.
*
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros">
<BOOST_VER>boost_1_48_0</BOOST_VER>
<THIRDPARTY_ROOT Condition="'$(THIRDPARTY_ROOT)' == '' ">C:\local\3rdparty</THIRDPARTY_ROOT>
</PropertyGroup>
<PropertyGroup />
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(THIRDPARTY_ROOT)\$(BOOST_VER)</AdditionalIncludeDirectories>
</ClCompile>
<Link />
</ItemDefinitionGroup>
<ItemGroup>
<BuildMacro Include="BOOST_VER">
<Value>$(BOOST_VER)</Value>
</BuildMacro>
<BuildMacro Include="THIRDPARTY_ROOT">
<Value>$(THIRDPARTY_ROOT)</Value>
</BuildMacro>
</ItemGroup>
</Project>
你爲什麼決定這樣的環境變量是正確的解決方案? – 2012-01-13 13:17:39
@CodyGray不是每個開發者都有相同的PC設置,並且存在相對路徑不起作用的情況,例如,第三方庫。它們在硬盤上只存在一次,而不是每個源存儲庫。 – pesche 2012-01-13 16:26:49