MSBuild Architecting a Customized Build System Rajeev Goel
MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft. com TLN 402 Software Development Engineer MSBuild Microsoft Corporation 1
Dogfooding Developer Tools Within Microsoft June 2002 (3+ years ago) Editor/Find In Files Help/Samples Project system/Intellisense/ Designers Build system (Visual Studio. NET 2003) Debugger 2
Dogfooding Developer Tools Within Microsoft September 2005 (now) 30% of Dev. Div code (. NET Framework + Visual Studio) now builds every day in the build lab using MSBuild and Team. Build! 100% conversion to MSBuild by March 2006 Single project file for command-line and Visual Studio IDE builds Full IDE development experience, including intellisense, refactoring, designers, etc. My mission: Help you do this too! 3
In This Session… Part 1. MSBuild Basics Part 2. The Power of Item Metadata Part 3. The Power of the MSBuild Task Part 4. Team Build 4
Part 1: MSBuild Basics 5
The Building Blocks Overall architecture of MSBuild and Team Build . NET Framework 2. 0 Redist Web Service MSBuild. exe Tasks Visual Studio 2005 project system MSBuild (core components) Engine Loggers Tasks . TARGETS Loggers Team Foundation Server Source control Work item tracking . NET Framework 2. 0 6
What Is MSBuild? A fully extensible build system that ships with the. NET Framework 2. 0. A build system that is seamlessly integrated with Visual Studio 2005. An XML file format for describing your project’s properties, items, and build process. A soon-to-be shipping product! November 7, 2005!! 7
MSBuild Basics 8
MSBuild File Format Basics (cont. ) Task Implementation public class Make. Dir : Task { private string[] directories; public string Directories { get {return directories; } set {directories = value; } } public override bool Execute() { foreach (string directory in directories) { System. IO. Directory. Create. Directory(directory); } return true; } } 9
Part 2: The Power of Item Metadata 10
Item Metadata <Item. Group> <Embedded. Resource Include=“c: BitmapsSplash. bmp”> <Culture>en-US</Culture> <Owner>Don B</Owner> </Embedded. Resource> <Embedded. Resource Include=“c: BitmapsAbout. bmp”> <Culture>it-CH</Culture> <Owner>Anders H</Owner> </Embedded. Resource> </Item. Group> Use item metadata to store additional information associated with each item Item metadata always follows the item around 11
Built-in Item Metadata Full. Path Root. Dir Filename Extension Relative. Directory Recursive. Dir Modified. Time Creation. Time Accessed. Time Identity <Embedded. Resource Include=“ c: PDC 2005MSBuild. Demo Splash. bmp”/> Root. Dir Relative. Dir Filename Extension 12
Batching Example: Bucketing items Build satellite assemblies by invoking “AL” once per Culture <AL Embed. Resources=“@(Embedded. Resource)” Output. Assembly=“%(Culture)Resources. dll” /> @(Embedded. Resource) %(Culture) 001. bmp en-US it-CH pa-IN en-US pa-IN 002. bmp 003. wmv 004. bmp 005. wmv 006. xml 13
Batching On Single Metadata 14
Batching (cont. ) Example: Bucketing items Build satellite assemblies, one per Culture/Extension <AL Embed. Resources=“@(Embedded. Resource)” Output. Assembly=“%(Culture)My%(Extension)Resources. dll” /> @(Embedded. Resource) %(Culture) %(Extension) 001. bmp en-US it-CH pa-IN en-US pa-IN . bmp. wmv. xml 002. bmp 003. wmv 004. bmp 005. wmv 006. xml 15
Batching (cont. ) Example: Looping Invoke a task once per item in your item list <Exec Command=“gacutil. exe /i %(All. Assemblies. Identity)” /> 16
Batching (cont. ) Example: Filtering Copy only the files in the @(Source. File) list that have a. TXT file extension <Copy Source. Files=“@(Source. File)” Destination. Folder=“bindebug” Condition=“ %(Extension) == ‘. TXT’ ” /> 17
Part 3: The Power Of The MSBuild Task 18
The <MSBuild …/> Task Executes target(s) in another MSBuild project Runs entirely in-process Never builds the same target in the same project twice within a build Used for communication between projects Gathering information from referenced projects Building child projects 19
Project-to-Project References <MSBuild Projects=“@(Project. Reference )”> Projects=“@(Project. Reference)”> <Output Task. Parameter=“ Target. Outputs” ” Item. Name=“ Resolved. Reference” ” /> Task. Parameter=“Target. Outputs Item. Name=“Resolved. Reference </MSBuild > </MSBuild> <Csc Sources=“. . . ” References=“@(Resolved. Reference )” /> References=“@(Resolved. Reference)” Automatically picks up the right configuration Automatically rebuilds the referenced project if necessary Automatically cleans the referenced project when parent is cleaned Referenced project need not be in the same. SLN 20
The MSBuild Task 21
Passing In Properties To The Child Project <Target Name=“Build. Debug. And. Release”> <MSBuild Projects=“My. App 1. vbproj” Targets=“Build” Properties=“Configuration=Debug” /> <MSBuild Projects=“My. App 1. vbproj” Targets=“Build” Properties=“Configuration=Release” /> </Target> The “Properties” parameter can be used to pass in global overriding properties into the child project Different sets of global properties cause new instances of the child project to get loaded 22
Part 4: Team Build 23
What Is Team Build? A fully automated build solution that is easy to use and configure Capable of a complete end-to-end build Seamlessly integrated into Visual Studio Team System and Team Foundation Server Fully extensible through standard MSBuild extensibility mechanisms In other words, it’s a build lab in a box 24
Team Build 25
Team Build Architecture Team Foundation Client Create build type Start build View Reports Drop Location Application Tier Team Build Web Services Build Machine Data Tier Team Foundation warehouse Sources Work items Team Build data MSBuild 26
Team Build Execution Get sources from source control Build projects (including code analysis) Run tests and gather code coverage Update work items Publish build outputs Produce build report and send mail 27
Building In The Future Example: Inlining task code. (Hypothetical only; will not compile. ) Example: Auto Tool. Task Generator. (Hypothetical only. ) <Project xmlns=“…”> xmlns Faster builds through Character. Replace” ” Language=“C#”> <Project xmlns=“…”> <Using. Task. Name=“Character. Replace xmlns<Using. Task public class Character. Replace : Task { … <Using. Tool. Task Name="Gac. Util" " Tool. Name=" gacutil. exe"> "> Name=" Tool. Name="gacutil. exe public override bool"Execute() <Parameter Name="Install. Assemblies" Type="stringarray " Switch="i"/> Name=" Type="stringarray" { Uninstall. Assemblies" <Parameter Name="Uninstall. Assemblies " Type="stringarray " Switch="u“/> Name=" Type="stringarray" Result = Input. Replace(Old. String, , New. String); ); <Parameter Name="Force. Install" " Type="boolean " Switch="f" /> Input. Replace(Old. String New. String Name=" Type="boolean" return true; <Parameter Name="No. Logo" " Type="boolean " Switch="nologo " Name=" Type="boolean" Switch="nologo" /> } </Using. Tool. Task> > </ } </Using. Task > </Using. Task> Multi-proc builds Distributed build Extensible mechanisms for achieving incremental builds Easier task authoring <Target Name=“Build”> Example: Inline your task code <Gac. Util =“@(Final. Output. Assembly)” )” <Gac. Util Install. Assemblies=“@( Install. Assemblies <Character. Replace Input=“$(Unescaped. Output. Path )” <Character. Replace Input=“$(Unescaped. Output. Path)” Force. Install=“true” /> Old. String=“” New. String=“\”> <Output Property. Name=“ Escaped. Output. Path” ” … /> Property. Name=“Escaped. Output. Path </Target> </Character. Replace> Example: Auto Tool. Task generator </Project> </Target> </Project> 28
Building In The Future (cont. ) Continuous Integration through Team Build Richer IDE integration; IDE becomes a visual build designer File format enhancements, including XML namespaces. SLN file format becomes MSBuild Debugging the build process 29
MSBuild Pseudo-Debugger 30
Call To Action Start converting your existing builds to MSBuild now! Watch for MSBuild cameos throughout PDC! Send product feedback, questions, and success stories to msbuild@microsoft. com We want your feedback! Rate this session online at http: //commnet. microsoftpdc. com 31
Community Resources For MSBuild Tools & Languages Track Lounge (Big Room) Either Faisal or Rajeev will be there all day Thursday. Other great sessions (presented earlier) TLNL 01 “MSBuild Tips and Tricks” TLN 301 “Behind the Scenes of Team Foundation Server” Join the MSBuild table at “Ask The Experts”. Thursday, 6: 30 pm, Big Room 32
Community Resources For MSBuild (cont. ) Demo bits Available through Comm. Net post-conference See me in the Tools & Languages Track Lounge Send mail to msbuild@microsoft. com Channel 9 wiki – http: //channel 9. msdn. com/wiki/default. aspx/MSBuild. Home. Page MSBuild MSDN Forums – http: //forums. microsoft. com/msdn/Show. Forum. aspx? Forum. ID=27 Latest MSBuild docs – http: //msdn 2. microsoft. com 33
And Finally … … Have A Great Time At The Party!!! 34
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. 35
- Slides: 35