MSBUILD

15. November 2006 18:13 by Mrojas in General  //  Tags:   //   Comments (0)

MSBuild

Microsoft has develop the Microsoft Build Engine (MSBuild). This is the new build platform for Microsoft and Visual Studio. It is an XML configuration (very similar to other build tools like ANT) It allows to orchestrate and build products in build lab environments where Visual Studio is not installed.

It is a great aid with other tools like CruiseControl.NET, relation that I will further elaborate in other posts.

The following is very simple MSBuils script

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

<PropertyGroup><OutputPath>.\bin</OutputPath></PropertyGroup>

<Target Name="HelloWorld">

<MakeDir Directories= "bin"/>

<Csc Sources="HellWorld.cs" TargetType="exe"

OutputAssembly=".\bin\HelloWorld.exe" />

</Target>

</Project>



This sample shows the basic structure of an MSBuild. This is a very basic script maybe not very useful, but general scripts will be made up of Several Targets, Properties and some dependencies between them.


Properties

To define properties just define your tags inside a <PropertyGroup> Tag. If you want for example to define an OutputPath property just do something like:


<PropertyGroup><OutputPath>.\bin</OutputPath></PropertyGroup>

And to use it just reference it as $(OutputPath)


Groups of files

You can specify groups of files with the ItemGroup tag

<ItemGroup>

<File_Image Include="$(OutputPath)\Image.jpg"/>

<cs_source Include=".\*.cs" Exclude=".\Foo1.cs" />

</ItemGroup>

And you will reference them like @(File_Image) and @(cs_source).


Dependencies between Targets


<Target Name="CreateOutputPath" Condition="!Exists('$(OutputPath)')">

<MakeDir Directories= "$(OutputPath)"/>

</Target>

<Target Name="FooCompilation" DependsOnTargets="CreateOutputPath"

Inputs=" Foo1.cs"

Outputs="$(OutputPath)\Foo1.exe">

</Target>