1 / 35

MSBuild: Architecting a Customized Build System

MSBuild: Architecting a Customized Build System. Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation. Dogfooding Developer Tools Within Microsoft June 2002 (3+ years ago). . . . . .

hisano
Télécharger la présentation

MSBuild: Architecting a Customized Build System

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Dogfooding Developer Tools Within MicrosoftJune 2002 (3+ years ago)     

  3. Dogfooding Developer Tools Within Microsoft September 2005 (now) • 30% of DevDiv code (.NET Framework + Visual Studio) now builds every dayin the build lab using MSBuild and TeamBuild! • 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!

  4. 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

  5. Part 1: MSBuild Basics

  6. Team Build .TARGETS Web Service Tasks Loggers Team Foundation Server Visual Studio 2005 project system MSBuild.exe MSBuild (core components) Work item tracking Source control Engine Loggers Tasks .TARGETS .NET Framework 2.0 The Building BlocksOverall architecture of MSBuild and Team Build .NET Framework 2.0 Redist

  7. 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!!

  8. MSBuild Basics

  9. MSBuild File Format Basics (cont.)Task Implementation public class MakeDir : 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.CreateDirectory(directory); } return true; } }

  10. Part 2: The Power of Item Metadata

  11. Item Metadata <ItemGroup> <EmbeddedResource Include=“c:\Bitmaps\Splash.bmp”> <Culture>en-US</Culture> <Owner>Don B</Owner> </EmbeddedResource> <EmbeddedResource Include=“c:\Bitmaps\About.bmp”> <Culture>it-CH</Culture> <Owner>Anders H</Owner> </EmbeddedResource> </ItemGroup> • Use item metadata to store additional information associated with each item • Item metadata always follows the item around

  12. Built-in Item Metadata FullPath RootDir Filename Extension RelativeDir Directory RecursiveDir ModifiedTime CreationTime AccessedTime Identity <EmbeddedResource Include=“ c:\PDC2005\MSBuildDemo\Splash.bmp”/> RelativeDir Filename RootDir Extension

  13. BatchingExample: Bucketing items Build satellite assemblies by invoking “AL” once per Culture <AL EmbedResources=“@(EmbeddedResource)” OutputAssembly=“%(Culture)\Resources.dll” /> @(EmbeddedResource) %(Culture) 001.bmp 002.bmp 003.wmv 004.bmp 005.wmv 006.xml

  14. Batching On Single Metadata

  15. Batching (cont.)Example: Bucketing items Build satellite assemblies, one per Culture/Extension <AL EmbedResources=“@(EmbeddedResource)” OutputAssembly=“%(Culture)\My%(Extension)\Resources.dll” /> @(EmbeddedResource) %(Culture) %(Extension) 001.bmp 002.bmp 003.wmv 004.bmp 005.wmv 006.xml

  16. Batching (cont.)Example: Looping • Invoke a task once per item in your item list <Exec Command=“gacutil.exe /i %(AllAssemblies.Identity)” />

  17. Batching (cont.)Example: Filtering • Copy only the files in the @(SourceFile) list that have a .TXT file extension <Copy SourceFiles=“@(SourceFile)” DestinationFolder=“bin\debug\” Condition=“ %(Extension) == ‘.TXT’ ” />

  18. Part 3: The Power Of The MSBuild Task

  19. 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

  20. Project-to-Project References <MSBuild Projects=“@(ProjectReference)”> <Output TaskParameter=“TargetOutputs” ItemName=“ResolvedReference” /> </MSBuild> <Csc Sources=“...” References=“@(ResolvedReference)” /> • 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

  21. The MSBuild Task

  22. Passing In Properties To The Child Project <Target Name=“BuildDebugAndRelease”> <MSBuild Projects=“MyApp1.vbproj” Targets=“Build” Properties=“Configuration=Debug” /> <MSBuild Projects=“MyApp1.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

  23. Part 4: Team Build

  24. 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

  25. Team Build

  26. Team BuildArchitecture Drop Location Team Foundation Client Create build type Start build View Reports Application Tier Build Machine Team Build Web Services Data Tier Sources Work items Team Build data MSBuild Team Foundation warehouse

  27. Produce build report and send mail Publish build outputs Updatework items Run tests and gather code coverage Build projects (including code analysis) Team BuildBuild Execution Get sources from source control

  28. Example: Auto ToolTask Generator. (Hypothetical only.) <Project xmlns=“…”> <UsingToolTask Name="GacUtil" ToolName="gacutil.exe"> <Parameter Name="InstallAssemblies" Type="stringarray" Switch="i"/> <Parameter Name="UninstallAssemblies" Type="stringarray" Switch="u“/> <Parameter Name="ForceInstall" Type="boolean" Switch="f" /> <Parameter Name="NoLogo" Type="boolean" Switch="nologo" /> </UsingToolTask> <Target Name=“Build”> <GacUtil InstallAssemblies=“@(FinalOutputAssembly)” ForceInstall=“true” /> </Target> </Project> Example: Inlining task code. (Hypothetical only; will not compile.) <Project xmlns=“…”> <UsingTask TaskName=“CharacterReplace” Language=“C#”> public class CharacterReplace : Task { … public override bool Execute() { Result = Input.Replace(OldString, NewString); return true; } } </UsingTask> <Target Name=“Build”> <CharacterReplace Input=“$(UnescapedOutputPath)” OldString=“\” NewString=“\\”> <Output PropertyName=“EscapedOutputPath” … /> </CharacterReplace> </Target> </Project> Building In The Future • Faster builds through • Multi-proc builds • Distributed build • Extensible mechanisms for achieving incremental builds • Easier task authoring • Example: Inline your task code • Example: Auto ToolTask generator

  29. 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

  30. MSBuild Pseudo-Debugger

  31. 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

  32. 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) • TLNL01 “MSBuild Tips and Tricks” • TLN301 “Behind the Scenes of Team Foundation Server” • Join the MSBuild table at “Ask The Experts”. Thursday, 6:30pm, Big Room

  33. Community Resources For MSBuild (cont.) • Demo bits • Available through CommNet post-conference • See me in the Tools & Languages Track Lounge • Send mail to msbuild@microsoft.com • Channel 9 wiki – http://channel9.msdn.com/wiki/default.aspx/MSBuild.HomePage • MSBuild MSDN Forums – http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=27 • Latest MSBuild docs – http://msdn2.microsoft.com

  34. … Have A Great Time At The Party!!! And Finally …

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

More Related