Below is my favorite MsBuild configuration. I use this on the go to check the status of my code especially after merging code from a remote branch.

D:\Code\Project1\Src>C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe /v:m /p:configuration=Release /m:4 /nr:False

But what exactly do the commands above represent? At the very highest level these are not actually commands but switches passed to MSBuild. They are the set of instructions to customize the build and pretty much the same thing used by all the automated build systems out there. So let’s go through each of the items above one by one.

D:\Code\Project1\Src> – This should the root directory where the solution is contained in. In MSbuild lingo it is the working directory and is required in case the specific projects eg .csproj are not contained in the same folder as the .sln file which is most often the case.

C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe – Of course this is the path to the MSbuild file.

Solution.sln – The solution file to build

/v:m – This is the verbosity i.e the control for the amount of information to be displayed. M represents minimal verbosity.

p:configuration=Release – Provides a provision to pass parameters in a name value pair. In this case we are telling MSbuild to use the release configuration. In an event that one wants to pass other parameter like the build number or as is the case of octopus deploy where the URL to the nugget package server is provided.

/m:4 – the maximum CPU count. From an object oriented perspective it is the number of MsBuild instances which will be running and hence can also be thought of as the number of concurrent projects to build. My machine is on 4 logical processors and hence right here I am making full use of each of them.

/nr:False – This is about node reuse. Essentially it can be thought of as the lifestyles as in Castle.Windsor. When it is set to False then all instances created will be discarded as soon as the build is over while when True then its equivalent to Castle’s singleton lifestyle.

There are quite a number of switches to be used but the above are what I consider a minimum viable product in terms of building a visual studio solution via the command line. The full guide to the MSBuild reference can be found on the MSDN website at the link below.

https://msdn.microsoft.com/en-us/library/ms164311.aspx

 

Leave a Reply

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