Geeks With Blogs
Gaurav Bodar - ALM Consultant, TFS specialist ALM, TFS, Agile, Scrum, Sharepoint, IT Service

Technorati Tags: ,,

 

What is MSBuild? MSBuild is a general-purpose build system created by Microsoft and is

used to build most Microsoft Visual Studio projects. MSBuild is shipped with the Microsoft

.NET Framework. What this means is that you do not need to have Visual Studio installed in

order to build your applications.

Project File Details

you should follow these

conventions for specifying the extension of the file:

 .proj A project file

 .targets A file that contains shared targets, which are imported into other files

 .props Default settings for a build process

 .tasks A file that contains Using Task declarations

Mainly MSBUILD definition is stored in two xsd files:

  •  Microsoft.Build.Core.xsd file describes all the fundamental elements that an MSBuild file can contain
  •  Microsoft.Build.Commonttypes.xsd defines all known elements; this is mainly used to describe the elements that Visual Studio–generated project files can contain.

Properties and Targets

MSBuild properties are simply key-value pairs. The key for the property is the name that you

will use to refer to the property. The value is its value. When you declare static properties,

they are always contained in a PropertyGroup element, which occurs directly within

the Project element.

simple example of declaring static properties:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>

<AppServer>\\sayedApp</AppServer>

<WebServer>\\sayedWeb</WebServer>

</PropertyGroup>

</Project>
MSBuild fundamentally has two execution elements: tasks and targets. A task is the smallest

unit of work in an MSBuild file, and a target is a sequential set of tasks. A task must always

be contained within a target. Here’s a sample that shows you the simplest MSBuild file that

contains a target:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Target Name="HelloWorld">

</Target>

</Project>

The command you will be invoking to start MSBuild is msbuild .exe. The basic usage for the command is as follows:


msbuild [INPUT_FILE] /t:[TARGETS_TO_EXECUTE]


Items

Building applications usually means dealing with many files. Because of this, you use

a specific construct when referencing files in MSBuild: items. Items are usually file-based

references, but they can be used for other purposes as well. When you

define a property, you are declaring a key-value pair, which is a one-to-one relationship.

When you declare items, one item can contain a list of many values. In terms of code,

a property is analogous to a variable and an item to an array. Take a look at how an item

is declared in the following snippet

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<ItemGroup>

<SolutionFile Include="..\Build.sln" />

</ItemGroup>

<Target Name="Print">

<Message Text="SolutionFile: @(SolutionFile)" />

</Target>

</Project>


Item Metadata

Another difference between properties and items is that items can have metadata associated with them. When you create an item, each of its elements is a full-fledged .NET object, which can have a set of values (metadata) associated with it.

To see how things change when an item contains more than one value, let’s examine

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"

ToolsVersion="4.0">

<ItemGroup>

<Compile Include="*.cs" />

</ItemGroup>

<Target Name="Print">

<Message Text="Compile fullpath: @(Compile->'%(FullPath)')" />

</Target>

</Project>

Item Transformation

Many times you would need to modify the Item without changing the existing item list. MSBuild has this feature inbuilt named transformation.

In the following example, a list of .resx files is transformed into a list of .resources files.


@(RESXFile->'%(filename).resources')

For MSBuild Command Line http://msdn.microsoft.com/en-us/library/vstudio/ms164311.aspx
MSBuild Reserved Properties http://msdn.microsoft.com/en-us/library/vstudio/ms164309.aspx

Item Meta data http://msdn.microsoft.com/en-us/library/ms164313.aspx

To find more MSBUILD Task

MSBuild Extension Pack (http://msbuildextensionpack.codeplex.com/)

Microsoft SDC Tasks (http://sdctasks.codeplex.com/)

MSBuild Community Tasks (http://msbuildtasks.tigris.org)

Important Toolset from Codeplex
http://msbuildshellex.codeplex.com/

Profiler http://msbuildprofiler.codeplex.com/

Third party Tool Sidekick http://www.attrice.info/msbuild/

http://msbuildlaunchpad.codeplex.com/

Posted on Wednesday, August 28, 2013 11:20 AM MSBUILD , tfs build | Back to top


Comments on this post: MSBuild Quick Start

# re: MSBuild Quick Start
Requesting Gravatar...
The article about MSBuild is very useful, informative and thanks for the same. The example of declaring static properties discussed in properties and targets section found to be very useful to me. It is illustrated perfectly and in a understandable manner. catalina island hotels
Left by rosemary on Mar 22, 2016 10:55 PM

# re: MSBuild Quick Start
Requesting Gravatar...
Thanks for the information. I've used this idea in my project and it really work fine on my end. - Mark Zokle
Left by George on Nov 02, 2016 12:30 AM

comments powered by Disqus

Copyright © Gaurav Bodar | Powered by: GeeksWithBlogs.net