370 likes | 797 Views
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). . . . . .
E N D
MSBuild: Architecting a Customized Build System Rajeev Goel, rgoel@microsoft.com TLN402 Software Development Engineer MSBuild Microsoft Corporation
Dogfooding Developer Tools Within MicrosoftJune 2002 (3+ years ago)
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!
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
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
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!!
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; } }
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
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
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
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
Batching (cont.)Example: Looping • Invoke a task once per item in your item list <Exec Command=“gacutil.exe /i %(AllAssemblies.Identity)” />
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’ ” />
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
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
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
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
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
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
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
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
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
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
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
… Have A Great Time At The Party!!! And Finally …
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.