35
MSBuild: Architecting a MSBuild: Architecting a Customized Build System Customized Build System Rajeev Goel, [email protected] Rajeev Goel, [email protected] TLN402 TLN402 Software Development Engineer Software Development Engineer MSBuild MSBuild Microsoft Corporation Microsoft Corporation

MSBuild: Architecting a Customized Build System Rajeev Goel, [email protected] TLN402 Software Development Engineer MSBuild Microsoft Corporation

Embed Size (px)

Citation preview

Page 1: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

MSBuild: Architecting a MSBuild: Architecting a Customized Build SystemCustomized Build System

Rajeev Goel, [email protected] Goel, [email protected] Development EngineerSoftware Development EngineerMSBuildMSBuildMicrosoft CorporationMicrosoft Corporation

Page 2: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

2

Dogfooding Developer Tools Within MicrosoftDogfooding Developer Tools Within MicrosoftJune 2002 (3+ years ago)June 2002 (3+ years ago)

DebuggerDebugger

Editor/Find In FilesEditor/Find In Files

Help/SamplesHelp/Samples

Project system/Intellisense/ Project system/Intellisense/ DesignersDesigners

Build system Build system (Visual Studio .NET (Visual Studio .NET 2003)2003)

Page 3: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

3

Dogfooding Developer Tools Within Microsoft Dogfooding Developer Tools Within Microsoft September 2005 (now)September 2005 (now)

30% of DevDiv code (.NET Framework + 30% of DevDiv code (.NET Framework + Visual Studio) now Visual Studio) now builds every daybuilds every day in in the build lab using MSBuild and the build lab using MSBuild and TeamBuild!TeamBuild!

100% conversion to MSBuild by March 2006100% conversion to MSBuild by March 2006

Single project file for command-line and Single project file for command-line and Visual Studio IDE buildsVisual Studio IDE builds

Full IDE development experience, including Full IDE development experience, including intellisense, refactoring, designers, etc.intellisense, refactoring, designers, etc.

My mission: Help you do this My mission: Help you do this too!too!

Page 4: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

4

In This Session…In This Session…

Part 1. MSBuild BasicsPart 1. MSBuild Basics

Part 2. The Power of Item MetadataPart 2. The Power of Item Metadata

Part 3. The Power of the MSBuild Part 3. The Power of the MSBuild TaskTask

Part 4. Team BuildPart 4. Team Build

Page 5: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

5

Part 1: MSBuild BasicsPart 1: MSBuild Basics

Page 6: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

6

The Building BlocksThe Building BlocksOverall architecture of MSBuild and Team Overall architecture of MSBuild and Team BuildBuild

.NET Framework 2.0.NET Framework 2.0

MSBuild.exeMSBuild.exeVisual Studio 2005 Visual Studio 2005

project systemproject system

MSBuild (core components)MSBuild (core components)EngineEngine

TasksTasks

LoggersLoggers

.TARGETS.TARGETS

Team Foundation Team Foundation ServerServer

Source Source controlcontrol

Work Work item item

trackingtracking

Team BuildTeam Build

Web ServiceWeb Service TasksTasks LoggersLoggers .TARGETS.TARGETS

.NE

T F

ram

ew

ork

2.0

Red

ist

.NE

T F

ram

ew

ork

2.0

Red

ist

Page 7: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

7

What Is MSBuild?What Is MSBuild?

A fully extensible build system that ships A fully extensible build system that ships with the .NET Framework 2.0.with the .NET Framework 2.0.

A build system that is seamlessly A build system that is seamlessly integrated with Visual Studio 2005.integrated with Visual Studio 2005.

An XML file format for describing your An XML file format for describing your project’s properties, items, and build project’s properties, items, and build process.process.

A soon-to-be shipping product! November A soon-to-be shipping product! November 7, 2005!!7, 2005!!

Page 8: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

8

MSBuild BasicsMSBuild Basics

Page 9: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

9

public class public class MakeDirMakeDir : Task : Task{{ private stringprivate string[][] directoriesdirectories;; public string public string DirectoriesDirectories {{ get {return get {return directoriesdirectories;};} set {set {directoriesdirectories = value;} = value;} }}

public override bool Execute()public override bool Execute() {{ foreach (string directory in directories)foreach (string directory in directories) {{ System.IO.System.IO.Directory.CreateDirectory(directory);Directory.CreateDirectory(directory); }} return true;return true; }}}}

MSBuild File Format Basics (cont.)MSBuild File Format Basics (cont.)Task ImplementationTask Implementation

Page 10: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

10

Part 2: The Power of Item Part 2: The Power of Item MetadataMetadata

Page 11: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

11

Item MetadataItem Metadata

Use item metadata to store additional Use item metadata to store additional information associated with each iteminformation associated with each item

Item metadata always follows the item Item metadata always follows the item aroundaround

<ItemGroup><ItemGroup>

<EmbeddedResource Include=“c:\Bitmaps\Splash.bmp”><EmbeddedResource Include=“c:\Bitmaps\Splash.bmp”> <Culture>en-US</Culture><Culture>en-US</Culture> <Owner>Don B</Owner><Owner>Don B</Owner> </EmbeddedResource></EmbeddedResource>

<EmbeddedResource Include=“c:\Bitmaps\About.bmp”><EmbeddedResource Include=“c:\Bitmaps\About.bmp”> <Culture>it-CH</Culture><Culture>it-CH</Culture> <Owner>Anders H</Owner><Owner>Anders H</Owner> </EmbeddedResource></EmbeddedResource>

</ItemGroup></ItemGroup>

Page 12: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

12

Built-in Item MetadataBuilt-in Item MetadataFullPathFullPath

RootDirRootDir

FilenameFilename

ExtensionExtension

RelativeDirRelativeDir

DirectoryDirectory

RecursiveDirRecursiveDir

ModifiedTimeModifiedTime

CreationTimeCreationTime

AccessedTimeAccessedTime

IdentityIdentity

<EmbeddedResource Include=“<EmbeddedResource Include=“ c:\c:\ PDC2005\MSBuildDemo\PDC2005\MSBuildDemo\ SplashSplash .bmp.bmp”/>”/>

RootDiRootDirr

RelativeDiRelativeDirr

FilenameFilename ExtensionExtension

Page 13: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

13

BatchingBatchingExample: Bucketing itemsExample: Bucketing items

Build satellite assemblies by invoking “AL” once per Build satellite assemblies by invoking “AL” once per CultureCulture

en-USen-US

it-CHit-CH

pa-INpa-IN

en-USen-US

en-USen-US

pa-INpa-IN

%(Culture)%(Culture)

001.bm001.bmpp002.bm002.bmpp003.wm003.wmvv004.bm004.bmpp005.wm005.wmvv006.xml006.xml

@(EmbeddedResource)@(EmbeddedResource)

<AL EmbedResources=““@(EmbeddedResource)” OutputAssembly=““%(Culture)\Resources.dll” />

Page 14: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

14

Batching On Single Batching On Single MetadataMetadata

Page 15: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

15

Batching (cont.)Batching (cont.)Example: Bucketing itemsExample: Bucketing items

Build satellite assemblies, one per Culture/ExtensionBuild satellite assemblies, one per Culture/Extension

en-USen-US .bmp.bmp

it-CHit-CH .bmp.bmp

pa-INpa-IN .wmv.wmv

en-USen-US .bmp.bmp

en-USen-US .wmv.wmv

pa-INpa-IN .xml.xml

%(Culture)%(Culture)

001.bm001.bmpp002.bm002.bmpp003.wm003.wmvv004.bm004.bmpp005.wm005.wmvv006.xml006.xml

@(EmbeddedResource)@(EmbeddedResource)

<AL EmbedResources=““@(EmbeddedResource)” OutputAssembly=““%(Culture)\My%(Extension)\Resources.dll” />

%(Extension)%(Extension)

Page 16: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

16

Batching (cont.)Batching (cont.)Example: LoopingExample: Looping

Invoke a task once per item in your Invoke a task once per item in your item listitem list

<Exec Command=“gacutil.exe /i <Exec Command=“gacutil.exe /i %(AllAssemblies.Identity)%(AllAssemblies.Identity)” />” />

Page 17: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

17

Batching (cont.)Batching (cont.)Example: FilteringExample: Filtering

Copy only the files in the Copy only the files in the @(SourceFile) list that have a .TXT @(SourceFile) list that have a .TXT file extensionfile extension

<Copy<Copy SourceFiles=“@(SourceFile)”SourceFiles=“@(SourceFile)” DestinationFolder=“bin\debug\”DestinationFolder=“bin\debug\” Condition=“ %(Extension) == ‘.TXT’ ”Condition=“ %(Extension) == ‘.TXT’ ”

/>/>

Page 18: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

18

Part 3: The Power Of The Part 3: The Power Of The MSBuild MSBuild TaskTask

Page 19: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

19

The <MSBuild …/> TaskThe <MSBuild …/> Task

Executes target(s) in another MSBuild Executes target(s) in another MSBuild projectproject

Runs entirely in-processRuns entirely in-process

Never builds the same target in the Never builds the same target in the same project twice within a buildsame project twice within a build

Used for communication between Used for communication between projectsprojects

Gathering information from referenced Gathering information from referenced projectsprojects

Building child projectsBuilding child projects

Page 20: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

20

Project-to-Project Project-to-Project ReferencesReferences

Automatically picks up the right Automatically picks up the right configurationconfiguration

Automatically rebuilds the referenced Automatically rebuilds the referenced project if necessaryproject if necessary

Automatically cleans the referenced project Automatically cleans the referenced project when parent is cleanedwhen parent is cleaned

Referenced project need not be in the Referenced project need not be in the same .SLNsame .SLN

<MSBuild Projects=“@(ProjectReference)”><MSBuild Projects=“@(ProjectReference)”> <Output TaskParameter=“TargetOutputs” ItemName=“ResolvedReference” /><Output TaskParameter=“TargetOutputs” ItemName=“ResolvedReference” /></MSBuild></MSBuild>

<Csc Sources=“...” References=“@(ResolvedReference)” /><Csc Sources=“...” References=“@(ResolvedReference)” />

Page 21: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

21

The MSBuild TaskThe MSBuild Task

Page 22: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

22

Passing In Properties To The Child Passing In Properties To The Child ProjectProject

The “Properties” parameter can be used to The “Properties” parameter can be used to pass in global overriding properties into pass in global overriding properties into the child projectthe child project

Different sets of global properties cause Different sets of global properties cause new instances of the child project to get new instances of the child project to get loadedloaded

<Target Name=“BuildDebugAndRelease”><Target Name=“BuildDebugAndRelease”>

<MSBuild Projects=“MyApp1.vbproj”<MSBuild Projects=“MyApp1.vbproj” Targets=“Build”Targets=“Build” Properties=“Configuration=Properties=“Configuration=DebugDebug” />” />

<MSBuild Projects=“MyApp1.vbproj”<MSBuild Projects=“MyApp1.vbproj” Targets=“Build”Targets=“Build” Properties=“Configuration=Properties=“Configuration=ReleaseRelease” />” />

</Target></Target>

Page 23: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

23

Part 4: Team BuildPart 4: Team Build

Page 24: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

24

What Is Team Build?What Is Team Build?

A fully automated build solution that is A fully automated build solution that is easy to use and configureeasy to use and configure

Capable of a complete end-to-end buildCapable of a complete end-to-end build

Seamlessly integrated into Visual Studio Seamlessly integrated into Visual Studio Team System and Team Foundation ServerTeam System and Team Foundation Server

Fully extensible through standard MSBuild Fully extensible through standard MSBuild extensibility mechanismsextensibility mechanisms

In other words, it’s a build lab in a In other words, it’s a build lab in a boxbox

Page 25: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

25

Team BuildTeam Build

Page 26: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

26

Team BuildTeam BuildArchitectureArchitecture

Team Foundation Team Foundation ClientClient

Application Application TierTier

Build Build MachineMachine

Create build Create build typetype Start buildStart build View ReportsView Reports

Team Build Team Build WebWeb

ServicesServices

MSBuildMSBuild

Drop Drop LocationLocation

Data TierData Tier SourcesSources Work itemsWork items Team Build Team Build datadata

Team Foundatio

n warehous

e

Page 27: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

27

Team BuildTeam BuildBuild ExecutionBuild Execution

Get sources from Get sources from source controlsource control

Produce build Produce build report and send report and send

mailmail

Publish Publish build outputsbuild outputs

UpdateUpdatework itemswork items

Build projects Build projects (including code (including code

analysis)analysis)

Run tests and Run tests and gather code gather code

coveragecoverage

Page 28: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

28

Building In The FutureBuilding In The Future

Faster builds throughFaster builds through

Multi-proc buildsMulti-proc builds

Distributed buildDistributed build

Extensible mechanisms for achieving Extensible mechanisms for achieving incremental buildsincremental builds

Easier task authoringEasier task authoring

Example: Inline your task codeExample: Inline your task code

Example: Auto ToolTask generatorExample: Auto ToolTask generator

Example: Inlining task code. (Hypothetical only; will not compile.)Example: Inlining task code. (Hypothetical only; will not compile.)

<Project xmlns=“…”><Project xmlns=“…”>

<UsingTask TaskName=“CharacterReplace” Language=“C#”><UsingTask TaskName=“CharacterReplace” Language=“C#”> public class CharacterReplace : Taskpublic class CharacterReplace : Task {{ … … public override bool Execute()public override bool Execute() {{ Result = Input.Replace(OldString, NewString);Result = Input.Replace(OldString, NewString); return true;return true; }} }} </UsingTask></UsingTask>

<Target Name=“Build”><Target Name=“Build”>

<CharacterReplace Input=“$(UnescapedOutputPath)”<CharacterReplace Input=“$(UnescapedOutputPath)” OldString=“\” NewString=“\\”>OldString=“\” NewString=“\\”> <Output PropertyName=“EscapedOutputPath” … /><Output PropertyName=“EscapedOutputPath” … /> </CharacterReplace></CharacterReplace>

</Target></Target>

</Project></Project>

Example: Auto ToolTask Generator. (Hypothetical only.)Example: Auto ToolTask Generator. (Hypothetical only.)

<Project xmlns=“…”><Project xmlns=“…”>

<UsingToolTask Name="GacUtil" ToolName="gacutil.exe"><UsingToolTask Name="GacUtil" ToolName="gacutil.exe"> <Parameter Name="InstallAssemblies" Type="stringarray" Switch="i"/><Parameter Name="InstallAssemblies" Type="stringarray" Switch="i"/> <Parameter Name="UninstallAssemblies" Type="stringarray" Switch="u“/><Parameter Name="UninstallAssemblies" Type="stringarray" Switch="u“/> <Parameter Name="ForceInstall" Type="boolean" Switch="f" /><Parameter Name="ForceInstall" Type="boolean" Switch="f" /> <Parameter Name="NoLogo" Type="boolean" Switch="nologo" /><Parameter Name="NoLogo" Type="boolean" Switch="nologo" /> </UsingToolTask></UsingToolTask>

<Target Name=“Build”><Target Name=“Build”>

<GacUtil InstallAssemblies=“@(FinalOutputAssembly)”<GacUtil InstallAssemblies=“@(FinalOutputAssembly)” ForceInstall=“true” />ForceInstall=“true” />

</Target></Target>

</Project></Project>

Page 29: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

29

Building In The Future (cont.)Building In The Future (cont.)

Continuous Integration through Team BuildContinuous Integration through Team Build

Richer IDE integration; IDE becomes a Richer IDE integration; IDE becomes a visual build designervisual build designer

File format enhancements, including XML File format enhancements, including XML namespacesnamespaces

.SLN file format becomes MSBuild.SLN file format becomes MSBuild

Debugging the build processDebugging the build process

Page 30: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

30

MSBuild Pseudo-DebuggerMSBuild Pseudo-Debugger

Page 31: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

31

Call To ActionCall To Action

Start converting your existing builds Start converting your existing builds to MSBuild now!to MSBuild now!

Watch for MSBuild cameos Watch for MSBuild cameos throughout PDC!throughout PDC!

Send product feedback, questions, Send product feedback, questions, and success stories to and success stories to [email protected]@microsoft.com

We want your feedback! Rate We want your feedback! Rate this session online at this session online at http://commnet.microsoftpdc.cohttp://commnet.microsoftpdc.com m

Page 32: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

32

Community Resources For Community Resources For MSBuildMSBuild

Tools & Languages Track Lounge (Big Tools & Languages Track Lounge (Big Room)Room)

Either Faisal or Rajeev will be there all day Either Faisal or Rajeev will be there all day Thursday.Thursday.

Other great sessions (presented earlier)Other great sessions (presented earlier)

TLNL01 “MSBuild Tips and Tricks”TLNL01 “MSBuild Tips and Tricks”

TLN301 “Behind the Scenes of Team TLN301 “Behind the Scenes of Team Foundation Server”Foundation Server”

Join the MSBuild table at “Ask The Join the MSBuild table at “Ask The Experts”. Thursday, 6:30pm, Big Experts”. Thursday, 6:30pm, Big RoomRoom

Page 33: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

33

Community Resources For MSBuild Community Resources For MSBuild (cont.)(cont.)

Demo bitsDemo bitsAvailable through CommNet post-Available through CommNet post-conferenceconferenceSee me in the Tools & Languages Track See me in the Tools & Languages Track LoungeLoungeSend mail to [email protected] mail to [email protected]

Channel 9 wiki – Channel 9 wiki – http://channel9.msdn.com/wiki/default.aspx/MSBuild.Homhttp://channel9.msdn.com/wiki/default.aspx/MSBuild.HomePageePage

MSBuild MSDN Forums – MSBuild MSDN Forums – http://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=27ForumID=27

Latest MSBuild docs – Latest MSBuild docs – http://msdn2.microsoft.comhttp://msdn2.microsoft.com

Page 34: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

34

… … Have A Great Time At The Have A Great Time At The Party!!!Party!!!

And Finally …And Finally …

Page 35: MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.