close
Msbuild

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=
..\Output"
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;" />
 </Target>
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.

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

<Target Name="Post-Copy" DependsOnTargets="Compile">
 <Message Text ="Copying Files..." />
 <Copy SourceFiles="@(ImgFiles)" DestinationFolder="$(ArtifactsPath)" />
 </Target>
 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

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'" 
 Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\
 WebApplications\Microsoft.WebApplication.targets" />
<Import Condition="'$(IsDesktopBuild)' == 'false'" 
 Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\
 WebApplications\Microsoft.WebApplication.targets" />
References

MSDN MSBuild Reference

Tags : msbuild
Byron Pate

The author Byron Pate