tags:

views:

72

answers:

2

Hi, I wish to start using MS-Build. I have lots of projects which I build manually (from Visual Studio) as of now. I want to automate build process and preferably from a machine onto which I don't wish to install Visual Studio. I started reading about MS-Build on MSDN. But I am yet to get a step by step guidance where to start and how to do. My questions are like:

  1. How can I start MS-Build? Is there any download-able?
  2. What is the first step?
  3. How to create an MS-Build script?

And a lot similar questions. Can somebody guide me?

+3  A: 

MS Build comes with the .NET Framework itself and the executable (msbuild.exe) is located in the .NET-framework directory, something like (depending on version):

  • C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319
  • C:\WINDOWS\Microsoft.NET\Framework\v3.5
  • C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

(The right version is also in %path% when using the "Visual Studio command prompt" from the start menu.)

MsBuild files are xml-files. You can start by making a new text file, lets say "c:\myscript.msbuild", and copy-paste this to the file:

<Project DefaultTargets="MyTarget" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
  <Target Name="MyTarget">
    <Message Text="Hello world!" Importance="high"/>
  </Target>
</Project>

Then go to command prompt and type:

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\msbuild.exe c:\myscript.msbuild

That is a good start. :)

Then you can customize the targets and properties. Second example:

<Project DefaultTargets="All" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
  <PropertyGroup Condition="'$(MyCondition)' == 'x'" >
    <MyProperty>World2</MyProperty>
  </PropertyGroup>
  <Target Name="MyTarget">
    <Message Text="Hello" Importance="high"/>
    <Message Text="$(MyProperty)" Importance="high"/>
  </Target>
  <Target Name="MyTarget2">
  </Target>
  <Target Name="All">
     <CallTarget Targets="MyTarget" />
     <CallTarget Targets="MyTarget2" />
  </Target>
</Project>

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\msbuild.exe c:\myscript.msbuild /target:mytarget /property:MyCondition=x

You can have also build files inside build-files.

<Project DefaultTargets="MyTarget" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
  <Import Project="MyExternalProperties.msbuild"/>
  <Target Name="MyTarget">
    <Exec Command="echo Hello world 3"/>
  </Target>
</Project>
Tuomas Hietanen
@Tuomas: Thanks a lot. This is going to be the most decent start for me. I shall now learn how to write the build file for my project.
Kangkan
+2  A: 

MSBuild is similar to other build products like NAnt (just in case you've used one of those), but it is still different in a few respects.

Here is a good start page on MSDN. There are a truckload of different MSBuild task libraries released under various licences, most that i have seen are completely free to use and come with source code. Probably the two biggest are:

Other good places to get info:

That should be enough to get started. If you can't find a task to do what you want, just write it yourseld - it is very easy.

slugster
Thanks. Though I could not make out much from the start page at MSDN, I hope, the other community projects will enhance my capabilities on MSBuild once I be able to use MSBuild.
Kangkan
Thanks, I have added the link to my book there as well. It is the best single source for info on MSBuild.
Sayed Ibrahim Hashimi
@Sayed: Thanks a lot.
Kangkan