Download presentation
Presentation is loading. Please wait.
Published byAnn Hutchinson Modified over 9 years ago
1
Tips & Tricks: Extending MSBuild with Tasks, Loggers, and Targets Faisal Mohamood (faisalmo@microsoft.com) TLNL01 Program Manager - MSBuild Microsoft Corporation
2
MSBuild – Tips & Tricks 2 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
3
MSBuild – Tips & Tricks 3 MSBuild in 5 minutes MyCoolApp true $(AppName).exe <Csc Sources=“@(Compile)” EmitDebugInformation=“$(DebugSymbols)” OutputAssembly=“$(OutputAssembly)”/>
4
MSBuild – Tips & Tricks 4 #1: Editing a project using Visual Studio 2005 Opening a project file for edit is 4 clicks away from within Visual Studio! When editing, you get full Intellisense based on the Project File Format Schema Right Click on the project name in Solution Explorer and “Unload Project” Right Click on the unloaded project in Solution Explorer and “Edit Project”
5
MSBuild – Tips & Tricks 5 #2: Customizing the Build <MakeDir Condition=“!Exists(‘@(PublishDir)’)” Directories=“@(PublishDir)” /> <Copy SourceFiles=“$(TargetPath)” DestinationFolder=“@(PublishDir)” /> How do I run pre-build and post-build steps using built-in MSBuild features?
6
MSBuild – Tips & Tricks 6 #3: Customizing with more granularity How do I run custom steps during arbitrary points in the build process – for example, what if I wanted to delete all files from c:\temp\publish as a part of Clean target? $(CleanDependsOn);MyClean
7
MSBuild – Tips & Tricks 7 #4: Using built-in metadata %(FullPath)%(RootDir)%(Filename)%(Extension)%(RelativeDir)%(Directory) %(RecursiveDir) %(Identity) %(ModifiedTime) %(CreationTime) %(AccessedTime) <Copy SourceFiles=“@(Compile)” DestinationFiles=“%(Compile.Filename).bak” />
8
MSBuild – Tips & Tricks 8 #5: Copying files recursively How can I use MSBuild constructs to copy all the contents of a folder from one directory to another? <Copy SourceFiles=“@(Files)” DestinationFolder=“C:\foocopy\%(RecursiveDir)” />
9
MSBuild – Tips & Tricks 9 #6: Building Incrementally How can I run the target only to transform those XML files that have been added (or changed) since the last build?
10
MSBuild – Tips & Tricks 10 #6: Building Incrementally <TargetName=“TransformXmlToHtml” Inputs=“@(XmlFile)” Outputs=“@(XmlFile->’%(Filename).html’)”> For items that have a 1:1 mapping between inputs and outputs, you can use Target Level Dependency Analysis by explicitly defining your inputs and outputs
11
MSBuild – Tips & Tricks 11 #7: Invoking one target from another A target that has built once will not build again during the same build session <MSBuild Projects=“myproject.proj” Targets=“RunUnitTests” />
12
MSBuild – Tips & Tricks 12 #8: Executing the same target multiple times How can I invoke the same target more than once?
13
MSBuild – Tips & Tricks 13 #8: Executing the same target multiple times Invoke the target using the MSBuild task but with different “properties” <MSBuild Projects=“$(MSBuildProjectFile)” Targets=“CalculateUnitTestCoverage” Properties=“Stage=BeforeBuild” /> <MSBuild Projects=“$(MSBuildProjectFile)” Targets=“CalculateUnitTestCoverage” Properties=“Stage=AfterBuild” />
14
MSBuild – Tips & Tricks 14 #9: Gathering performance summary “Somehow, my build has slowed down tremendously. I need to find out what’s going on!” C:\project> msbuild build.proj /ConsoleLoggerParameters:PerformanceSummary C:\project> msbuild build.proj /verbosity:Diagnostic Use the /ConsoleLoggerParameters switch or the Diagnostic verbosity to gather performance statistics.
15
MSBuild – Tips & Tricks 15 How do I do this? I’ve got a bunch of code that I’d like to open in Visual Studio, but all I have is a ton of source code with no Visual Studio project or solution I’d like to open for edit and browse using Visual Studio Is this possible?
16
MSBuild – Tips & Tricks 16 #10: Coolest trick of the day! Simply create a.csproj or.vbproj file that recursively adds all files to a Compile item, and additionally imports Microsoft.CSharp.targets or Microsoft.VisualBasic.targets
17
MSBuild – Tips & Tricks 17 Additional Resources Go to the Advanced MSBuild Breakout Session by Rajeev Goel – today @5pm Stop by the MSBuild table at Ask the Experts – Thursday 6:30pm @ The Big Room Visit the Tools & Languages Track Lounge (Big Room) Try out the MSBuild Hands On Lab here at the PDC if you are new to MSBuild Visit the MSBuild Wiki http://channel9.msdn.com/wiki/default.aspx/MSBuild.HomePage Post a question on the MSDN Forums – http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=27 Send mail to msbuild@microsoft.com
18
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.