Skip to content

MSBuild Tips & Tricks

Kirill Osenkov edited this page May 25, 2016 · 21 revisions

#MSBuild.exe /pp MSBuild preprocessor. Pass /pp to the command line to create a single huge XML project file with all project imports inlined in the correct order. This is useful to investigate the ordering of evaluation and execution. Example:

msbuild MyProject.csproj /pp:inlined.proj

#MSBuild.exe /m Parallel build. Many people still don't know that they can significantly speed up their builds by passing /m to MSBuild.exe.

#EnvironmentVariables

  • MSBUILDTARGETOUTPUTLOGGING - set this to enable printing all target outputs to the log.
  • MSBUILDLOGTASKINPUTS - log task inputs (not needed if there are any diagnostic loggers already).
  • MSBUILDEMITSOLUTION - save the generated .proj file for the .sln that is used to build the solution.
  • MSBUILDENABLEALLPROPERTYFUNCTIONS - enable additional property functions.
  • MSBUILDLOGCODETASKFACTORYOUTPUT - dump generated code for task to a .txt file in the TEMP directory

#TreatAsLocalProperty If MSBuild.exe is passed properties on the command line, such as /p:Platform=AnyCPU then this value overrides whatever assignments you have to that property inside property groups. For instance, <Platform>x86</Platform> will be ignored. To make sure your local assignment to properties overrides whatever they pass on the command line, add the following at the top of your MSBuild project file:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" TreatAsLocalProperty="Platform">

This will make sure that your local assignments to the Platform property are respected. You can specify multiple properties in TreatAsLocalProperty separated by semicolon.