Using command-line MSBuild tool to build .Net Project/Solution

In this post, I will walk you through on how you can use command-line MSBuild tool to build a .net solution or project.

Basic Info from MSBuild GitHub page:

The Microsoft Build Engine is a platform for building applications. This engine, which is also known as MSBuild, provides an XML schema for a project file that controls how the build platform processes and builds software. Visual Studio uses MSBuild, but MSBuild does not depend on Visual Studio. By invoking msbuild.exe on your project or solution file, you can orchestrate and build products in environments where Visual Studio isn’t installed.

It is a handy tool for build servers. Usually, you would want to avoid bloating build-server with the whole Visual Studio installation. Instead, you can leverage the MSBuild command-line tool to build your application. Following are few ways you can use msbuild.exe

 

Prerequisites:

Build Tools for Visual Studio 2017 ( or for your version of VS)

Optional: you could add MSBuild location to your System Environments Variable for easy access.

You can find the MSBuild exe in

 C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin

Build a solution:

msbuild  NameOfYourSoution.sln

Build a specific project

msbuild NameOfYourProject.csproj

The project could be c# or vb or any other .Net compatible project.

 

Both of the above commands will build a debug version of your solution/project. What if you want to specify  Release Configuration or other Configuration you created?

This can be easily handled with MSBuild properties arguments.

Specifying MSBuild Configuration parameter:

msbuild NameOfYourProject.csproj /p:Configuration=Release

 

Rebuilding your project with MSBuild command-line

This can be achieved with /t: argument where t stands for Targets

msbuild NameOfYourProject.csproj /t:rebuild

 

Cleaning your Solution/Project with MSBuild command-line

msbuild NameOfYourSolution.sln /t:clean

 

Refererences:

MSBuild command-line reference on MS-Docs

MSBuild Documentation

 

Sandeep

a dev, an amateur photographer and a father

 

One thought on “Using command-line MSBuild tool to build .Net Project/Solution

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: