How to build .Net projects manually

We can build .Net projects manually by making a call to the Microsoft’s builder engine called MSBuilder.exe, which comes with Visual Studio so it should be placed around some folder there depending on the version of Visual Studio that you have. It is already integrated into Visual Studio, but if you want to call it manually you can make a call to it using a command line and sending which project to build and its options. As writing that each time we want to build would be hazardous and time-consuming it is better to create a script to do all the stuff just on executing it. This way, also, we can prepare different scripts with different types of builds: dev, staging, production, …

Here you have an example of what it could be a ReleaseBuild.bat:

set projectPath=..\folderWithYourSolutionCode
set buildConfiguration=Release
rem set buildTargets=CoreAnalysis
rem set buildTargets=BuildAll;DistributeApp
set buildTargets=BuildAll

cd %projectPath%
C:\WINDOWS\Microsoft.NET\Framework\v4.0.10568\msbuild %projectPath%\MyConfigFile.msbuild /p:Configuration=%buildConfiguration% /p:ToolsPath=%toolsPath% /t:%buildTargets% /maxcpucount

rem /p:BuildType=Server

pause

Notice that we are setting the path were the project files are, though what we really want is the .msbuild file with all the details of the build, file which should normally be placed at the same place where the project files are. You may want to check how to create your own .msbuild file from scratch.

Now you only need to open PowerShell or the standard Windows Command Prompt, move to the folder where you have this script using “cd”, execute it just writing its name, and voilá, the build starts. PowerShell is a new command-line shell with more features than the default one, it is worth using it even if only because it’s not black&white and makes reading the output much easier.

Tip: You can write part of the file/folder name and press tab to have it fully written, or press tab more times if there are others with similar name.

Leave a Reply

Close Bitnami banner
Bitnami