A while back I wrote about Reserved Properties in MSBuild 3.5, now its time to update that post to include reserved properties for MSBuild 4.0. There are a number of new properties here is the list:

•    MSBuild
•    MSBuildBinPath
•    MSBuildExtensionsPath
•    MSBuildExtensionsPath32
•    MSBuildExtensionsPath64
•    MSBuildLastTaskResult
•    MSBuildNodeCount
•    MSBuildOverrideTasksPath
•    MSBuildProgramFiles32
•    MSBuildProjectDefaultTargets
•    MSBuildProjectDirectory
•    MSBuildProjectDirectoryNoRoot
•    MSBuildProjectExtension
•    MSBuildProjectFile
•    MSBuildProjectFullPath
•    MSBuildProjectName
•    MSBuildStartupDirectory
•    MSBuildThisFile
•    MSBuildThisFileDirectory
•    MSBuildThisFileDirectoryNoRoot
•    MSBuildThisFileExtension
•    MSBuildThisFileFullPath
•    MSBuildThisFileName
•    MSBuildToolsPath
•    MSBuildToolsVersion

If you want to see what the values are you can execute this simple proj file that I created.

01<project toolsversion="4.0" defaulttargets="PrintValues" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
02 
03  <target name="PrintValues">
04    <message text="MSBuild: $(MSBuild)">
05    <message text="MSBuildBinPath: $(MSBuildBinPath)">
06    <message text="MSBuildExtensionsPath: $(MSBuildExtensionsPath)">
07    <message text="MSBuildExtensionsPath32: $(MSBuildExtensionsPath32)">
08    <message text="MSBuildExtensionsPath64: $(MSBuildExtensionsPath64)">
09    <message text="MSBuildLastTaskResult: $(MSBuildLastTaskResult)">
10    <message text="MSBuildNodeCount: $(MSBuildNodeCount)">
11    <message text="MSBuildOverrideTasksPath: $(MSBuildOverrideTasksPath)">
12    <message text="MSBuildProgramFiles32: $(MSBuildProgramFiles32)">
13    <message text="MSBuildProjectDefaultTargets: $(MSBuildProjectDefaultTargets)">
14    <message text="MSBuildProjectDirectory: $(MSBuildProjectDirectory)">
15    <message text="MSBuildProjectDirectoryNoRoot: $(MSBuildProjectDirectoryNoRoot)">
16    <message text="MSBuildProjectExtension: $(MSBuildProjectExtension)">
17    <message text="MSBuildProjectFile: $(MSBuildProjectFile)">
18    <message text="MSBuildProjectFullPath: $(MSBuildProjectFullPath)">
19    <message text="MSBuildProjectName: $(MSBuildProjectName)">
20    <message text="MSBuildStartupDirectory: $(MSBuildStartupDirectory)">
21    <message text="MSBuildThisFile: $(MSBuildThisFile)">
22    <message text="MSBuildThisFileDirectory: $(MSBuildThisFileDirectory)">
23    <message text="MSBuildThisFileDirectoryNoRoot: $(MSBuildThisFileDirectoryNoRoot)">
24    <message text="MSBuildThisFileExtension: $(MSBuildThisFileExtension)">
25    <message text="MSBuildThisFileFullPath: $(MSBuildThisFileFullPath)">
26    <message text="MSBuildThisFileName: $(MSBuildThisFileName)">
27    <message text="MSBuildToolsPath: $(MSBuildToolsPath)">
28    <message text="MSBuildToolsVersion: $(MSBuildToolsVersion)">
29  </message></message></message></message></message></message></message></message></message></message></message></message></message></message></message></message></message></message></message></message></message></message></message></message></message></target>
30 
31</project>

For me the results are:

01C:\Data\Development\My Code\Community\MSBuild>msbuild ReservedProps02.proj /m /nologo
02Build started 3/18/2010 12:43:49 AM.
03     1>Project "C:\Data\Development\My Code\Community\MSBuild\ReservedProps02.proj" on node 1 (default targets).
04     1>PrintValues:
05         MSBuild:
06         MSBuildBinPath: C:\Windows\Microsoft.NET\Framework\v4.0.30128
07         MSBuildExtensionsPath: C:\Program Files (x86)\MSBuild
08         MSBuildExtensionsPath32: C:\Program Files (x86)\MSBuild
09         MSBuildExtensionsPath64: C:\Program Files\MSBuild
10         MSBuildLastTaskResult: true
11         MSBuildNodeCount: 8
12         MSBuildOverrideTasksPath:
13         MSBuildProgramFiles32: C:\Program Files (x86)
14         MSBuildProjectDefaultTargets: PrintValues
15         MSBuildProjectDirectory: C:\Data\Development\My Code\Community\MSBuild
16         MSBuildProjectDirectoryNoRoot: Data\Development\My Code\Community\MSBuild
17         MSBuildProjectExtension: .proj
18         MSBuildProjectFile: ReservedProps02.proj
19         MSBuildProjectFullPath: C:\Data\Development\My Code\Community\MSBuild\ReservedProps02.proj
20         MSBuildProjectName: ReservedProps02
21         MSBuildStartupDirectory: C:\Data\Development\My Code\Community\MSBuild
22         MSBuildThisFile: ReservedProps02.proj
23         MSBuildThisFileDirectory: C:\Data\Development\My Code\Community\MSBuild\
24         MSBuildThisFileDirectoryNoRoot: Data\Development\My Code\Community\MSBuild\
25         MSBuildThisFileExtension: .proj
26         MSBuildThisFileFullPath: C:\Data\Development\My Code\Community\MSBuild\ReservedProps02.proj
27         MSBuildThisFileName: ReservedProps02
28         MSBuildToolsPath: C:\Windows\Microsoft.NET\Framework\v4.0.30128
29         MSBuildToolsVersion: 4.0
30     1>Done Building Project "C:\Data\Development\My Code\Community\MSBuild\ReservedProps02.proj" (default targets
31       ).

If you want to see the correct valus for MSBuildNodeCount make sure to use the /m switch when you invoke msbuild.exe.

I won’t go over these properties in detail here, because they are mostly obvious but I would like to point out a couple really useful properties, those include.

MSBuildThisFile
MSBuildThisFileDirectory
MSBuildThisFileDirectoryNoRoot

These properties can be used to locate the path to the file that you are currently in. So if you have a shared .targets file and it will execute an .exe in the same folder you can use the MSBuildThisFileDirectory property to resolve the full path to that tool reliably. This has historically been difficult. See a recent question on Stackoverflow.com about it at How can I get the path of the current msbuild file? If you are not using MSBuild 4.0 and need to resolve the location to a .targets file then see that post for what you will need to do.


Comment Section



Comments are closed.