Export (0) Print
Expand All

MSBuild Reserved and Well-Known Properties

MSBuild provides a set of predefined properties that store information about the project file and the MSBuild binaries. These properties are evaluated in the same manner as other MSBuild properties. For example, to use the MSBuildProjectFile property, you type $(MSBuildProjectFile).

Reserved and well-known properties are always predefined by MSBuild with the values described in the table below. Reserved properties cannot be overridden, but well-known properties can. You can override well-known properties with identically-named environment properties, global properties and/or properties that are declared the project file.

The following table describes the MSBuild predefined properties.

Property

Description

Reserved or Well-Known

MSBuildBinPath

The absolute path of the folder where the MSBuild binaries that are currently being used are located (for example, C:\Windows\Microsoft.Net\Framework\versionNumber\). This property is useful if you have to refer to files in the MSBuild directory.

Reserved

MSBuildExtensionsPath

In .NET 4.0 and later versions, there is no difference between the default values of MSBuildExtensionsPath and MSBuildExtensionsPath32. You can set the environment variable MSBUILDLEGACYEXTENSIONSPATH to a non-null value to enable the behavior of the default value of MSBuildExtensionsPath in previous versions.

In .NET 3.5 and earlier, the default value of MSBuildExtensionsPath points to the path of the MSBuild subfolder under the \Program Files\ or \Program Files (x86)\ folder depending on the bitness of the current process. For example, for a 32-bit process on a 64-bit machine, this property points to the \Program Files (x86)\ folder. For a 64-bit process on a 64-bit machine, this property points to the \Program Files\ folder.

This location is a useful place to put custom target files. For example, your target files could be installed at \Program Files\MSBuild\MyFiles\Northwind.targets and then imported in project files by using this XML code:

<Import Project="$(MSBuildExtensionsPath)\MyFiles\Northwind.targets"/>

Well-Known

MSBuildExtensionsPath32

The path of the MSBuild subfolder under the \Program Files\ or \Program Files (x86)\ folder. This path always points to the 32-bit \Program Files\ folder on a 32-bit machine and \Program Files (x86)\ on a 64-bit machine. See also MSBuildExtensionsPath and MSBuildExtensionsPath64.

Well-Known

MSBuildExtensionsPath64

The path of the MSBuild subfolder under the \Program Files\ folder. For a 64-bit machine, this path always points to the \Program Files\ folder. For a 32-bit machine, this path is blank. See also MSBuildExtensionsPath and MSBuildExtensionsPath32.

Well-Known

MSBuildLastTaskResult

true if the previous task completed without any errors (even if there were warnings), or false if the previous task had errors. Typically, when an error occurs in a task, the error is the last thing that happens in that project. Therefore, the value of this property is never false, except in these scenarios:

Reserved

MSBuildNodeCount

The maximum number of concurrent processes that are used when building. This is the value that you specified for /maxcpucount on the command line. If you specified /maxcpucount without specifying a value, then MSBuildNodeCount specifies the number of processors in the computer. For more information, see MSBuild Command-Line Reference and Building Multiple Projects in Parallel with MSBuild.

Reserved

MSBuildProgramFiles32

The location of the 32-bit program folder; for example, C:\Program Files (x86).

Reserved

MSBuildProjectDefaultTargets

The complete list of targets that are specified in the DefaultTargets attribute of the Project element. For example, the following Project element would have an MSBuildDefaultTargets property value of A;B;C:

<Project DefaultTargets="A;B;C" >

Reserved

MSBuildProjectDirectory

The absolute path of the directory where the project file is located, for example C:\MyCompany\MyProduct\.

Reserved

MSBuildProjectDirectoryNoRoot

The value of the MSBuildProjectDirectory property, excluding the root drive.

Reserved

MSBuildProjectExtension

The file name extension of the project file, including the period; for example, .proj.

Reserved

MSBuildProjectFile

The complete file name of the project file, including the file name extension; for example, MyApp.proj.

Reserved

MSBuildProjectFullPath

The absolute path and complete file name of the project file, including the file name extension; for example, C:\MyCompany\MyProduct\MyApp.proj.

Reserved

MSBuildProjectName

The file name of the project file without the file name extension; for example, MyApp.

Reserved

MSBuildStartupDirectory

The absolute path of the folder where MSBuild is called. By using this property, you can build everything below a specific point in a project tree without creating dirs.proj files in every directory. Instead, you have just one project—for example, c:\traversal.proj, as shown here:

<Project ...>
    <ItemGroup>
        <ProjectFiles  
           Include="$
           (MSBuildStartupDirectory)
           **\*.csproj"/>
    </ItemGroup>
    <Target Name="build">
        <MSBuild    
        Projects="@(ProjectFiles)"/>
    </Target>
</Project>

To build at any point in the tree, type:

msbuild c:\traversal.proj

Reserved

MSBuildThisFile

The file name and file extension portion of MSBuildThisFileFullPath.

Reserved

MSBuildThisFileDirectory

The directory portion of MSBuildThisFileFullPath.

Reserved

MSBuildThisFileDirectoryNoRoot

The directory portion of MSBuildThisFileFullPath, excluding the root drive.

Reserved

MSBuildThisFileExtension

The file name extension portion of MSBuildThisFileFullPath.

Reserved

MSBuildThisFileFullPath

The absolute path of the project or targets file that contains the target that is running.

TipTip

The MSBuildThisFileFullPath property enables the specification of a relative path in a targets file that's relative to the targets file and not relative to the original project file.

Reserved

MSBuildThisFileName

The file name portion of MSBuildThisFileFullPath, without the file name extension.

Reserved

MSBuildToolsPath

The installation path of the MSBuild version that's associated with the value of MSBuildToolsVersion.

This property cannot be overridden.

Reserved

MSBuildToolsVersion

The version of the MSBuild Toolset that is used to build the project.

NoteNote

An MSBuild Toolset consists of tasks, targets, and tools that are used to build an application. The tools include compilers such as csc.exe and vbc.exe. For more information, see MSBuild Toolset (ToolsVersion), and Standard and Custom Toolset Configurations.

Reserved

Show:
© 2014 Microsoft