An  MSBuild Cheatsheet of handy references I’ve used for automating with MSBuild.

Reference Paths

Specify the path(s) to Project Reference DLLs. The ReferencePath property allows you to add a series of paths that MSBUILD will check, overriding any project-based references.

MSBUILD.EXE /p:"ReferencePath=<Path1;Path2;Path3>"
Build Output Location

To change where MSBuild puts the build output. You can use a relative path or full path.

MSBUILD.EXE /p:"OutputPath=
Using Quotes

In MSBuild scripts, to use quotes in commands use the &quot; characters.

<Target Name="SVN-LIB">
 <Exec Command="svn export &quot;$(SVNPathLib)&quot; &quot;$(ReferencePath)&quot;" />
Build Configuration

Specify the build configuration and platform.

MSBUILD.EXE /p:"Platform=x64" /p:"Configuration=Release"
Copying Files

To Copy files to your output location using the Copy task with an Item.

 <ImgFile Include="$(SourceDir)\Images\*.png" />

<Target Name="Post-Copy" DependsOnTargets="Compile">
 <Message Text ="Copying Files..." />
 <Copy SourceFiles="@(ImgFiles)" DestinationFolder="$(ArtifactsPath)" />
 Case is Important

MSBuild CheatsheetWhen creating MSBuild Scripts, the casing of the XML nodes and attributes matters. Using lower case on attributes could result in an MSBuild error indicating the attribute is unknown.

<Target name=”Default”>
is not the same as
<Target Name=”Default”>

If your case is wrong you’ll get an error like: MSB4066: The attribute “name” in element is unrecognized.


MSB4064: The “Retries” parameter is not supported by the “Copy” task. This error usually means you’re targetting v10.0 of MSBuild but you only have v9.00 installed. Use the IsDesktopBuild condition to use v9.0 when not in Visual Studio.

<Import Condition="'$(IsDesktopBuild)' == 'true'" 
 WebApplications\Microsoft.WebApplication.targets" />
<Import Condition="'$(IsDesktopBuild)' == 'false'" 
 WebApplications\Microsoft.WebApplication.targets" />

MSDN MSBuild Reference

Tags : msbuild
Byron Pate

The author Byron Pate