4 out of 5 rated this helpful - Rate this topic

MSBuild Reserved Properties

MSBuild provides a set of reserved properties that store information about the project file and the MSBuild binaries. These properties are evaluated the same as other MSBuild properties. For example, to use the MSBuildProjectFile property, you would type:

$(MSBuildProjectFile)

The following table describes the MSBuild reserved properties.

Property

Description

MSBuildProjectDirectory

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

MSBuildProjectFile

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

MSBuildProjectExtension

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

MSBuildProjectFullPath

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

MSBuildProjectName

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

MSBuildBinPath

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

MSBuildProjectDefaultTargets

The complete list of targets 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" >

MSBuildExtensionsPath

The MSBuild folder under the Program Files directory. This location is a useful place to put custom target files. For example, your targets files could be installed at \Program Files\MSBuild\MyFiles\Northwind.targets and then imported in project files with the following XML.

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

MSBuildStartupDirectory

The absolute path of the directory where MSBuild is invoked.

This allows you to go to any point in a project tree and build everything below that point without having to create "dirs.proj"-type files in every directory. Instead, you have only a single project, like this example called c:\traversal.proj:

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

Then at any point in the tree you would type:

msbuild c:\traversal.proj
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
MSBuildExtensionsPath is different on X64 machines.
The path resolves to C:\Program Files (X86)\Msbuild on X64 machines. If you have tools like Sandcastle, you may need to copy some of your targets files/directorys from here to C:\ProgramFiles\Msbuild. Stylecop may cause problems with BE0065 errors on an X64 OS if you included the msbuild extensions and your project references them.
MSBuildBinPath affected by toolsversion
I discovered that if the /toolsversion switch is set to 3.5 when running msbuild,

C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe /toolsversion:3.5

then MSBuild does, indeed, show c:\WINDOWS\Microsoft.NET\Framework\v3.5 as the value for MSBuildBinPath. It would appear that the default tools version is 2.
Re: doc wrong for MSBuildBinPath
I felt that this should be the way Alexey described, but I ran MSBuild from the 3.5 directory (C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe) and the value I got for MSBuildBinPath was "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727". I'm not sure if this is a bug that only happens in some PCs, but at least be aware that this can be the result.
Re: doc wrong for MSBuildBinPath
The doc is fine as it says: "The absolute path of the directory where the MSBuild binaries that are currently being used are located". So, for example, in .NET 3.5 it's usually something like C:\WINNT\Microsoft.NET\Framework\v3.5 where MSBuild 3.0 binaries are located. BTW, in case of .NET 3.5, C# 3.0 compiler is also located at that folder.
doc wrong for MSBuildBinPath
MSBuildBinPath points to the framework version directory not to the location of the

The absolute path of the directory where the MSBuild binaries that are currently being used are located,

So if you need to find out where the compiler is don't use MSBuildBinPath in 3.x because the complier is actually in the 2.0 directory.