Introduction of MSbuild

Hi Guys,

can u pl help me anyone Introduction of MSbuild?



  • Rajesh Kumar

    Rajesh Kumar 

    MSBuild Overview

    The Microsoft Build Engine (MSBuild) is the new build platform for Microsoft and Visual Studio. MSBuild is completely transparent with regards to how it processes and builds software, enabling developers to orchestrate and build products in build lab environments where Visual Studio is not installed. This topic provides brief overviews of:

    • The basic elements of an MSBuild project file.
    • How MSBuild is used to build projects.
    • The advanced features of MSBuild.
    • How Visual Studio uses MSBuild to build projects.

    Project File

    MSBuild introduces a new XML-based project file format that is simple to understand, easy to extend, and fully supported by Microsoft. The MSBuild project file format enables developers to fully describe what items need to be built as well as how they need to be built with different platforms and configurations. In addition, the project file format enables developers to author re-usable build rules that can be factored into separate files so that builds can be performed consistently across different projects within their product. The following sections describe some of the basic elements of the MSBuild project file format.


    Items represent inputs into the build system and are grouped into item collections based on their user-defined collection names. These item collections can be used as parameters for tasks, which use the individual items contained in the collection to perform the steps of the build process.

    Items are declared in the project file by creating an element with the name of the item collection as a child of an ItemGroupelement. For example, the following code creates an item collection named Compile, which includes two files.

        <Compile Include = "file1.cs"/>
        <Compile Include = "file2.cs"/>

    You reference item collections throughout the project file with the syntax @(ItemCollectionName). For example, you reference the item collection in the example above with @(Compile).

    Items can be declared using wildcards and may contain additional metadata for more advanced build scenarios. For more information on items, see MSBuild Items.


    Properties represent key/value pairs that can be used to configure builds. Items and properties differ in the following ways:

    • Items are stored in collections, while properties contain a single scalar value.
    • Items cannot be removed from item collections, while properties can have their values changed after they are defined.
    • Items can contain metadata and can use the %(ItemMetadata) notation, while properties cannot.

    Properties are declared by creating an element with the name of the property as a child of a PropertyGroup element. For example, the following code creates a property named BuildDir with a value of Build.


    You reference properties throughout the project file with the syntax $(PropertyName). For example, you reference the property in the example above with $(BuildDir). For more information on properties, see MSBuild Properties.


    Tasks are reusable units of executable code used by MSBuild projects to perform build operations. For example, a task might compile input files or run an external tool. Once created, tasks can be shared and reused by different developers in different projects.

    The execution logic of a task is written in managed code and mapped to MSBuild with the UsingTask element. You can write your own task by authoring a managed type that implements the ITask interface. For more information on writing tasks, see How to: Write a Task.

    MSBuild ships with many common tasks such as Copy, which copies files, MakeDir, which creates directories, and Csc, which compiles Visual C# source code files. For a complete list of available tasks and usage information, see MSBuild Task Reference.

    You execute a task in an MSBuild project file by creating an element with the name of the task as a child of a Targetelement. Tasks usually accept parameters, which are passed as attributes of the element. MSBuild item collections and properties can be used as parameters. For example, the following code calls the MakeDir task and passes it the value of the BuildDir property declared in the previous example.

    <Target Name="MakeBuildDirectory">
            Directories="$(BuildDir)" />

    For more information on tasks, see MSBuild Tasks.


    Targets group tasks together in a particular order and expose sections of the project file as entry points into the build process. Targets are often grouped into logical sections to allow for expansion and increase readability. Breaking the build steps into many targets allows you to call one piece of the build process from other targets without having to copy that section of code into each target. For example, if several entry points into the build process require references to be built, you can create a target that builds references and run that target from every necessary entry point.

    Targets are declared in the project file with the Target element. For example, the following code creates a target named Compile, which then calls the Csc task with the item collection declared in the previous example.

    <Target Name="Compile">
        <Csc Sources="@(Compile)" />

    In more advanced scenarios targets can describe relationships between each other and perform dependency analysis, which allows whole sections of the build process to be skipped if that target is up-to-date. For more information on targets, see MSBuild Targets.

    Building with MSBuild

    You run MSBuild from the command line by passing a project file to MSBuild.exe with the appropriate command line options. Command line options allow you to set properties, execute specific targets, and specify loggers. For example, you would use the following command line syntax to build the file MyProj.proj with the Configuration property set to Debug.

    MSBuild.exe MyProj.proj /property:Configuration=Debug

    For more information on MSBuild command line options, see MSBuild Command Line Reference.

    Security noteSecurity Note:
    Before you build a downloaded project, determine the trustworthiness of the code. MSBuild project files have the ability to execute tasks that can damage your system.

    Advanced concepts

    MSBuild can be used for more advanced operations during builds, such as logging errors, warnings, and messages to the console or other loggers, performing dependency analysis on targets, and batching tasks and targets on item metadata. For more information on these advanced concepts, see MSBuild Advanced Concepts.

    Visual Studio Integration

    Visual Studio uses the MSBuild project file format to store build information about managed projects. Project settings added and changed through Visual Studio are reflected in the .*proj file that is generated for each project. Visual Studio uses a hosted instance of MSBuild to build managed projects, meaning that a managed project can be built in Visual Studio and from the command line (even without Visual Studio installed), with identical results. For more information on how Visual Studio uses MSBuild, see MSBuild Advanced Concepts.



  • Rambabu Muppuri

    Rambabu Muppuri 

    hi raj , thanks for ur comments ..could u pl let me know how can we increment version numbers through msbuild tool..i have written below xml tag but which is not working help me..
    <Target Name=”Version”>if its possible send one exmaple with version numbers increment..

    <Message Text=”Version: $(Major).$(Minor).$(Build).$(Revision)”/>

    <AssemblyInfo CodeLanguage=”VB”

    OutputFile=”My Project\AssemblyInfo.vb”











    Condition=”$(Revision) != ‘0’ “/>

  • Rajesh Kumar

    Rajesh Kumar 

    Long time back same thing i did using Apache ant, you can find logic here


    meanwhile, I will try to create using MSBuild in free time.

Tagged : / / / /

MSBuild Tutorial Reference for Beginner | MSBuild Learning Resources | scmGalaxy


Walkthrough: Creating an MSBuild Project File from Scratch

How to: Write a Simple MSBuild Project

MSBuild Basics

Build Your Project File from Scratch using MSBuild

Tagged : / / / / / / / / / / / /

Extension used in DOTNET and MSBuild Projects

A popular convention for generic use. Commonly used by a main build script.
.targets files are those which is meant to be imported into other files using the Import element. Since these files are strictly re-useable they don’t actually build anything. They typically are missing the properties and item values to actually build anything.
Language specific convention where **** represents the language short acronym.
Well-known extensions:
.csproj    | C#
.vbproj    | VB.NET
.vcxproj   | Visual C++
.dbproj    | Database project
.fsproj    | F#
.pyproj    | IronPython
.rbproj    | IronRuby
.wixproj   | Windows Installer XML (WiX)
.vdproj    | Visual Studio Deployment Project
.isproj    | InstallShield
.pssproj   | PowerShell
.modelproj | Modeling project
A project property sheet used by Visual C++ projects (.vcxproj).
A common include file to be imported by a calling MSBuild project. Contains a list of <UsingTask> elements.
(This is a related convention if not strictly-speaking a file extension.)
A common include file to be imported by a calling MSBuild project. Contains “various properties related to shared utilities used during the build and deployment processes as well as any other common settings” (Sayed Ibrahim Hashimi, 2009).
Tagged : / / / / / / / / /

Introduction to MSBuild – Quick Intro Guide


Introduction to MSBuild

  • Microsoft supported build engine
  • XML-based configuration file
  • Intellisense available from Visual Studio using supplied schema
  • Ships with .NET Framework 2.0, it is NOT part of Team Foundation Server
  • Both Visual Studio and Team Foundation Server leverage MSBuild
  • Command-line utility – MSBuild.exe

MSBuild Concepts

  1. Project
  2. Property
  3. Item
  4. Target
  5. Task


–        The root concept in MSBuild

–        Defines the build process




–        Name/value pairs


–        Set of objects (commonly files)

–        Can specify meta-data to be applied to the objects



–        Defines a number of sequential tasks

–        Projects can have initial and/or default targets



–        Performs an operation

–        Uses properties and items

–        Extensible


        Directories="$(BuildDir)" />

Some Reference Link:

Tagged : / / / / / / /

Running MSBuild 4.0 and MSBuild 3.5 on Continuous Integration


With Visual Studio 2010 RC released recently, we jumped on the release and began to code with VS2010.  One issue that popped up was that now all builds were targeting MSBuild 4.0.

That doesn’t seem to be a big problem until our CruiseControl CI server kicked in, downloaded our updated code and failed building the upgraded projects.

Fortunately there is a very quick solution to this little problem.  There are a couple of requirements.

1. You need to have VS2010 RC installed somewhere
2. You need to download the .Net Framework 4.0 (I recommend the full version and not just the Client Profile, it ensures you don’t miss anything)

To fix, do the following:

1. download and install the .Net Framework 4.0 on the CI server (then restart the server)
2. on the computer where VS2010 RC is installed go to the following path:
3. copy the v10.0 folder located in that directory into the CI server at the same path (or wherever our MSbuild path is on the CI server)
4. Once that is done, edit the ccnet.config file at the tag and change it to the new .Net 4.0 Framework installed (you should only need to change the section “\v3.5\” to “\v4.0.xxxxx\”

Hope this helps

Tagged : / / / / / / / / / / / / / / /