Friday, March 14, 2008

MSBuild for VCProj Projects

For those who don't know about MSBuild, please check my latest post MSBuild.

MSBuild is the utility made by microsoft for command line building, one replacement for the Unix make system. MSBuild could be directly applied to the C# or VB Projects, and by that we can add tasks to tell the MSBuild utility that we want them to be made with/before/after the compilation process. VCBuild is the utility provided with visual studio .net for building the visual C++ projects of the visual studio .net. Unfortunately, the VCBuild doesn't have the luxury of adding tasks to the building process. The question now, how can we make use of the visual studio projects for C++, with making some sort of command line building that gives us the freedom to really automate that process ?

The key for this operation is that MSBuild provices a built-in task for VCBuild. We can make a seperate file that the vcproj file, and use it to execute VCBuild over the vcproj file we have to make the operation we want. The good thing is that the VCBuild task of the MSBuild gives us the real control over the compilation process, like if we are actually making the compilation of our own. Follows are some examples for the use of the VCBuild tasks:

<VCBuild Projects="MyProject.vcproj" Clean="true" />

This line asks the compiler to clean the project MyProject.vcproj

< VCBuild Projects = "MyProject.vcproj"
  Configuration    = "Release|Win32"   />

This line asks the compiler to build the project MyProject.vcproj with the configuration "Release|Win32"

using such command we can build the complete set of configurations we would like to have (for cleaning, building in debug, building in release, and anything else we want), besides making any operation we would like to consider as a build event (like copying the output file to some directory, and so on) with each. Example of an MSBuild project file for VC Projects is attached with this post.

Another Trick: Packing Projects into a solution

Like it is that VCBuild is a task that can be performed within MSBuild tasks, MSBuild is a task that can be performed withing MSBuild project files too. Using such task we can make packing for our projects to make a solution-like file, just the way we did it before with the VCBuild.

Attachements:

MSBuild

For every development environment there is, it must be found someway to make the command line build for large projects. For example, for the GNU C++, there is the make files, that are actually some form of command script automation to perform some tasks, and this is used to make the compilation of the projects in GNU C++. For the Microsoft Visual Studio .NET, MSBuild is the method you can use to perform the command line build, and that's what we care to speak about today.

For every C# or VB project made by Visual Studio .net, MSBuild utility can be used to build, rebuild, or clean the whole project, just using the command line (like: MSBuild.exe MyProj.csproj /property: Configuration=Debug). Also, you can add tasks to the project files you have so that they can perform while building. This thing can actually be very helpful in the field of making some building events, like post or pre build events, or making some way for custom building for the projects). The MSBuild tasks can vary from very simple commands, like copying or deleting a file, to more complex tasks like Csc (using the command line building for C Sharp files), to even more and more complex tasks like MSBuild or VCBuild, to evenly custom tasks, the ones you make and provide a reference to their definitions. For more infromation about MSBuild, about MSBuild tasks, what are the built in ones, how to implement a task, or how to use them, please check the following references.

References