Setting Up MSBuild


You can download MSBuild bundled together with Visual Studio or you can grab a standalone installer. If it is a build server you need standalone version. You can find all downloads at https://visualstudio.microsoft.com/downloads/. For standalone installations pick  Build Tools for Visual Studio in Tools section. At this time the download looks like this:

When MSBuild tools are installed it is helpful to add MSBuild bin folder to System Environment variable Path like shown below:

If it is a standalone installation it is going to be under C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin or something similar. After that is done you can test MSBuild in command line shell of your choice. Here we are using Windows power shell because it is available out of the box, but you could also use Windows Terminal or Alacritty. Open windows power shell and enter: msbuild -version. The result should be similar to one below:

If you see version displayed you have successfully configured Microsoft Build.

Extending MSBuild

Microsoft build is very powerful tool on its own. As first image describes it comes with variety of project build support, most used of them being csharp and visual basic compilers in a form of Roslyn:

But you can extend it to support your specific use case. WiX Toolset is one amazing tool helping build Microsoft Installer packages. MSBuild Community Tasks also offer some convenient functionality independent of project you are trying to build.

Wix Toolset

Go to https://wixtoolset.org/releases/ and download latest 3.x version. At the time of writing 4.x is not considered stable to be used in production. It points to GitHub releases page. Go ahead and download wix311.exe and install it. When installed you get 2 things. Plethora of tools installed under C:\Program Files (x86)\WiX Toolset v3.11\bin and extended MSBuild functionality. Additionally you can install Visual studio extension. It can also be found under https://wixtoolset.org/releases/ Visual Studio 2019 specific version can be found here. When VS extension is installed you can start authoring Setup Projects in visual studio:


You will still need to do some research before creating your MSI's. The documentation can be found here. There are some gotchas regarding wix.targets location. You can read more about it here.

MSBuild Community Tasks

Community Tasks can be downloaded from releases GitHub page.When it is installed you can test it out with a simple project file:

<project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <import project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
  <target name="test">
    <math.add numbers="4;3">
      <output taskparameter="Result" propertyname="Result"></output>
    </math.add>
    <message text="Add 4 + 3 = $(Result)" Importance="high" ></message>
  </target>
</project>

Save this file as test.proj and call msbuild. the result should be like shown below:

There are much more useful tasks in MSBuild  Community Tasks extension. You can manipulate zip files, read and write xml and download web content.

With MSBuild in place you can start authoring and building projects you need. Check out MSBuild command line reference, it is nice!


Related articles

Placeholder "LocalizeWeb2016" failed