When you build projects, it is often necessary to set build options using information that is not in the project file or the files that comprise your project. This information is typically stored in environment variables.
Referencing Environment Variables
All environment variables are available to the Microsoft Build Engine (MSBuild) project file as properties.
Note |
|---|
| If the project file contains an explicit definition of a property that has the same name as an environment variable, the property in the project file overrides the value of the environment variable. |
To use an environment variable in an MSBuild project
You can use a Condition attribute to provide a default value for a property if the environment variable was not set.
To provide a default value for a property
Example
The following project file uses environment variables to specify the location of directories.
<Project DefaultTargets="FakeBuild">
<PropertyGroup>
<FinalOutput>$(BIN_PATH)\myassembly.dll</FinalOutput>
<ToolsPath Condition=" '$(ToolsPath)' == '' ">
C:\Tools
</ToolsPath>
</PropertyGroup>
<Target Name="FakeBuild">
<Message Text="Building $(FinalOutput) using the tools at $(ToolsPath)..."/>
</Target>
</Project> See Also