msbuild unveiled n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
MSBuild Unveiled PowerPoint Presentation
Download Presentation
MSBuild Unveiled

Loading in 2 Seconds...

play fullscreen
1 / 22

MSBuild Unveiled - PowerPoint PPT Presentation


  • 84 Views
  • Uploaded on

MSBuild Unveiled. Peter Schneider MVP Visual Developer – Visual C# MCT, MCSD.NET, MCAD.NET, MCDBA ps@ugwa.net. In This Session…. MSBuild Architecture MSBuild – File Format MSBuild – Tips & Tricks. Abracadabra. VS Build System. Pre build step 0011010101 1110010110 1101100111 0010100111

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

MSBuild Unveiled


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
msbuild unveiled

MSBuild Unveiled

Peter SchneiderMVP Visual Developer – Visual C#MCT, MCSD.NET, MCAD.NET, MCDBAps@ugwa.net

in this session
In This Session…
  • MSBuild Architecture
  • MSBuild – File Format
  • MSBuild – Tips & Tricks
visual studio net 2002 2003

Abracadabra

VS Build System

Pre build step

0011010101

1110010110

1101100111

0010100111

Post build step

Produces

Authors

PROJECT FILE

- $%#^$&%

- @$#%$^#

Final Product

Visual Studio .NET 2002/2003

Feeds

msbuild design goals

Final Product

MSBuild

Produces

Authors

Feeds

Authors

DEVELOPER

MSBuild Design Goals

PROJECT FILE

<Project>

<Property … />

<Item … />

<Target … />

</Project>

msbuild in 5 minutes
MSBuild in 5 minutes
  • The underlying build engine in Visual Studio 2005
  • Fully open and published XML file format for describing build
  • Visual Studio 2005 build is fully customizable
  • You extend the build by writing managed code (tasks and loggers)
  • You don’t need the IDE to build Visual Studio projects
msbuild file format
MSBuild File Format

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

<PropertyGroup>

<AppName>MyCoolApp</AppName>

<DebugSymbols>true</DebugSymbols>

<OutputAssembly>$(AppName).exe</OutputAssembly>

</PropertyGroup>

<ItemGroup>

<Compile Include=“Hello.cs” />

<Compile Include=“Program.cs” />

</ItemGroup>

<Target Name=“Build”>

<Message Text=“Executing Build Target for App $(AppName)” />

<Csc Sources=“@(Compile)” EmitDebugInformation=“$(DebugSymbols)”

OutputAssembly=“$(OutputAssembly)”/>

</Target>

<Import Project=“Microsoft.CSharp.targets” />

</Project>

msbuild key components
MSBuild Key Components
  • Items
  • Properties
  • Targets
  • Tasks
build items
Build Items
  • Represent Input to the build system
  • Grouped into Item Collections
    • Use userdefined CollectionNames
  • Are used as Parameters for Tasks
  • Use Include and Exclude Attributes, Wildcards (**,*,?)

<ItemGroup>

<Compile Include=“Hello.cs” />

<Compile Include=“Program.cs” />

</ItemGroup>

build items1
Build Items
  • Reference ItemGroups with@(ItemCollectionName)Example:
  • <Csc Sources=„@(Compile)“/>

<ItemGroup>

<Compile Include=“Hello.cs” />

<Compile Include=“Program.cs” />

</ItemGroup>

build item metadata
Build Item Metadata
  • Items may contain MetaData

<ItemGroup>

<Compile Include=“Hello.cs”>

<Group>1</Group>

</Compile>

<Compile Include=“Program.cs”>

<Group>2</Group>

</Compile>

</ItemGroup>

  • Used for batching

<Target Name=“Testbatch”>

<Message Text=“@(Compile)” Condition=“ ’%(Group)’ == ‘1’ ”/>

</Target>

well known item meta data
Well Known Item Meta Data

%(FullPath)

%(RootDir)

%(Filename)

%(Extension)

%(RelativeDir)

%(Directory)

%(RecursiveDir)

%(Identity)

%(ModifiedTime)

%(CreationTime)

%(AccessedTime)

<ItemGroup>

<Compile Include=“*.cs” />

</ItemGroup>

<Target Name=“BackupSources”>

<Copy

SourceFiles=“@(Compile)”

DestinationFiles=“%(Compile.Filename).bak” />

</Target>

build properties
Build Properties
  • Properties are key/value pairs used to configure builds
  • Defined in PropertyGroups

<PropertyGroup>

<Configuration>Debug</Configuration>

</PropertyGroup>

  • Reference Properties with$(Propertyname)e.g. $(Configuration)
reserved properties
Reserved Properties
  • Some PropertyNames are reserved:
  • MSBuildProjectDirectory
  • MSBuildProjectFile
  • MSBuildProjectExtension
  • MSBuildProjectFullPath
  • MSBuildProjectName
  • MSBuildBinPath
  • MSBuildProjectDefaultTargets
  • MSBuildExtensionsPath
  • Environment Variables are accessible as Properties
setting properties
Setting Properties
  • You can set Properties from the commandline

MSBuild.exe MyProject.proj /p:Configuration=Debug

MSBuild.exe MyProject.proj /p:Configuration=Debug;Another=Test

  • You can set Properties depending on other properties

<DebugType Condition="'$(Flavor)'=='DEBUG'">full</DebugType>

build targets
Build Targets
  • Targets group tasks together in a particular order
  • Allows sections of the build process to be called individually (Commandline, CallTarget Task)

<Target Name=“Compile”>

<Csc Sources=“@(SourceFiles)”/>

</Target>

MSBuild.exe MyProject.proj /t:Compile

MSBuild.exe MyProject.proj /t:Clean;Compile

default targets
Default Targets
  • Use DefaultTargets Attribute

<Project DefaultTargets=“Compile”>

...

</Project>

  • InitialTargets are executed first

<Project InitialTargets=“Clean”>

...

</Project>

incremental builds
Incremental Builds
  • Reduce build time
  • Only builds targets which are out-of-date or not yet built
  • Specify Inputs and Outputs of the target

<Target Name=“Compile”

Inputs = “@(SourceFiles)”

Outputs = “HelloWorld.exe” >

<Csc Sources=“@(SourceFiles)” OutputAssembly=“HelloWorld.exe”/>

</Target>

build tasks
Build Tasks
  • A Task is a unit of executable code which performs atomic build operations

<Target Name=“MakePublishDirectory”>

<Message Text=“Creating Publish Directory”/>

<MakeDir Directories=“$(PublishDir)”/>

</Target>

build task outputs
Build Task Outputs
  • Task can return Output mapped to Items or Properties

<Target Name="CopyFiles">

<Copy SourceFiles="@(MySourceFiles)" DestinationFolder="@(MyDestFolder)">

<Output TaskParameter="CopiedFiles" ItemName="SuccessfullyCopiedFiles"/> </Copy>

<Message Text=“@(SuccessfullyCopiedFiles,”,”)”></Target>

build task continueonerror
Build Task ContinueOnError
  • Specify the ContinueOnError Attribute to succeed target for non-critical tasks
  • Other possibilities:

<Target Name=“SampleTarget">

<TaskOne ContinueOnError="false">

</TaskOne>

<TaskTwo> </TaskTwo>

<OnError ExecuteTargets="OtherTarget" />

</Target>

project elements
Project Elements
  • Use Choose, When, Otherwise Elements

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

<PropertyGroup>

<SampleProperty>Test</SampleProperty>

</PropertyGroup>

<Choose>

<When Condition=“’$(SampleProperty)’ ==‘Test’”>

<PropertyGroup>

</PropertyGroup>

</When>

<Otherwise>

</Otherwise>

</Choose>

</Project>

summary
Summary
  • Properties
  • Items
  • Targets
  • Tasks
  • Projects