| Mike 的个人资料FreeToDev日志列表 | 帮助 |
|
|
11月9日 Versioning Code in TFS 2010For those using TFS 2010, take a read of John Robbins new post TFS 2010 Build Number and Assembly File Versions: Completely In Sync with Only MSBuild 4.0 11月7日 Versioning Code in TFS - RevisedThis is a revised and combined post covering the two previous posts, Versioning Code in TFS Part 1 & Part 2. If you haven’t read those two posts, then this revised post is all you need to read. If you have read the two previous posts, then although similar, I recommend you read this revised post as it contains important corrections, updates and clarifications. Note that this post mostly relates to TFS 2008, though the concepts implied are not tied to a specific version of TFS. ____________________________________________________________________________________ The ProblemI’ve lost count of the number of blog posts, forum questions and internal emails that I have seen regarding problems with versioning assemblies in TFS. I believe the root cause of the problem is that many users have tried to migrate their existing versioning logic and code to work with TFS, blinded by the wealth of functionality that TFS has brought to the development process. The Truth
Some BasicsWhat is Versioning?Versioning refers to the process whereby code is compiled and ‘stamped’ with a version number that can distinguish it from previous or future builds of that code. What is a version number?There are two version numbers in .Net, the AssemblyVersion and the AssemblyFileVersion. Both follow the same format:
My first piece of advice is that you don’t keep the two in sync. The AssemblyVersion should rather be of the format:
The reason for this is that strong name signatures include the AssemblyVersion, which means that if you release an updated assembly, the code that references it will need to be updated too (unless you go the publisher policy route, but let’s try keeping things simple). The AssemblyFileVersion is the attribute that should be updated with every build you perform, and therein lays the problem. How? I would estimate that in 99% of builds, the format of the build number will be
The Static parts are easy and they will most likely equate to those used in the AssemblyVersion. The calculated part is really up to you. It could be a date format e.g. mmdd or possibly the number of days since a given milestone date etc. The iterative part is where the trouble lies. All versioning tasks need to provide the same essential logic. They need to calculate your build number and provide a unique incremental value for every build. To ensure that the incremental value is unique, most versioning solutions check out a file, alter it and check the file back in. Lots of people including myself first used the AssemblyInfo task (which has now been included in the MSBuild Extension Pack), and encountered numerous painful ‘cannot determine the workspace’ errors, or you were likely to be caught by check-in policies or duplicate attributes. All issues can be resolved, but too many people have had a hard time using this task for versioning. It’s a great task, but not for versioning. If you managed to get around the AssemblyInfo task issues, or your own problems with creating a task that checked out a file, incremented the value and then checked it in again, well done... and welcome to continuous merging issues! TFS 2005 / 2008 don’t support multiple pending merge entries for a single file, so you have to perform continuous merging. This isn’t a big issue with versioning tasks, however the problem with continuously checking out and in the versioning file(s) is that you get loads of noise on the pending merges table and if you do merge multiple version files, you will likely have to manually resolve the final version. My second piece of advice is don’t check your versioning files in and out during the build process. As discussed above, it creates noise and merge hassles. As long as you’re versioning logic can be related to the TFS Build Number, I see no benefit in having this source control operation take place. The SolutionTFS provides a build number for every build it initiates. The format is
e.g.
To accomplish versioning, use the <revision> part of the build number. TFS will provide an incremented revision for every build, whether the previous build succeeded or not. All you need to do is provide a task that takes the build number as input, then emits your version number as output. The logic within the task is up to you. Because your build is based on the build number, you can easily locate the label associated with the build. In summary
Implementing the SolutionIf you don’t want to write your own task to implement versioning, the MSBuild Extension Pack provides various tasks to assist you with versioning. AssemblyInfo Task [MSBuild.ExtensionPack.Framework.AssemblyInfo] The original AssemblyInfo task has been added to the MSBuild Extension Pack and received various small tweaks. As mentioned, I’m not a fan of using this for versioning, but if you must, then below is an abbreviated sample: <Project DefaultTargets="DesktopBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> <!-- ADD AND CONFIGURE THIS PROPERTY GROUP --> <!-- SET THIS TO NON-EXISTENT FILE TO FORCE REBUILD. --> <!-- OVERRIDE AFTERGET--> <!-- SET THE ASSEMBLYINFOFILES ITEMS DYNAMICALLY --> <Exec WorkingDirectory="$(SolutionRoot)" Command="$(TF) checkout /recursive "@(AssemblyInfoFiles)""/> <!-- OVERRIDE AFTERCOMPILE-->
TFSVersion Task [MSBuild.ExtensionPack.VisualStudio.TfsVersion] The TFSVersion task provides the more lightweight versioning that I have described and is what I use on all projects. Please Note: The output of GetVersion should not be used to change the $(BuildNumber). <Project DefaultTargets="DesktopBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> <!-- DEFINE WHICH FILES TO VERSION --> <!-- OVERRIDE BUILDNUMBEROVERRIDETARGET --> <!-- OVERRIDE AFTERGET --> SQLVersion Task [MSBuild.ExtensionPack.SqlServer.SqlVersion] The SqlVersion task provides the ability to manage multiple build versions in a simple database table. Please Note: The output of GetVersion should not be used to change the $(BuildNumber). <Project DefaultTargets="DesktopBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> <!-- DEFINE WHICH FILES TO VERSION --> <!-- OVERRIDE BUILDNUMBEROVERRIDETARGET --> <!-- Get the latest build number and increment as necessary --> <!-- OVERRIDE AFTERGET --> Version 3.5.5.0 of the MSBuild Extension Pack will provide an additional file based versioning task, but the above three, especially the TFSVersion task should meet most needs. I’ve disabled comments on this blog as the spam filters on live spaces are not sufficient. If you have any feedback, please use the feedback URL found in the MSBuild Extension Pack help. Mike 9月30日 Planning for Team Foundation Server 2010 (Rosario)Brian Harry posted an interesting blog which outlines some of the steps that can and should be taken in planning for Rosario. Note that this information is based on assumption and subject to change. Below is a summarised view that may be handy for your Rosario budget meeting… [Download pdf] 7月24日 Versioning Code in TFS - Part 27 Nov 2009: Update In Versioning Code in TFS - Part 1 I covered most of my thoughts on the matter. I've since helped a colleague out with implementing code versioning using GetBuildNumber and SetBuildNumber in the FTDTFSBuild task. I was disappointed that the experience wasn't as smooth as it could have been and following a few discussions, a few changes have been made to the FTDTFSBuild Task to improve the functionality and user experience. These have all shipped in the latest beta release of the FreeToDev MSBuild Tasks Suite. Summary of ChangesName changes to alleviate confusion:
Enhancements
Updated Sample <!-- 1. Import the Tasks--> 6月2日 Versioning Code in TFS - Part 17 Nov 2009: Update 24 July 2008 UPDATE: Part 2 is available. I’ve lost count of the number of blog posts, forum questions and internal emails that I have seen regarding problems with versioning assemblies in TFS. I’ve made various responses to them and in many said I would put together some thoughts to clarify my thinking on the matter... I’ve finally got round to doing it... The ProblemI believe the root cause of the problem is that many users have tried to migrate their existing versioning logic and code to work with TFS, blinded by the wealth of functionality that TFS has brought to the development process. The truth is that TFS provides the basic fundamentals of iterative versioning out the box. Versioning AssembliesLet’s start with some basic fundamentals. What’s a version number? There are two version numbers in .net, the AssemblyVersion and the AssemblyFileVersion. Both follow the same format: <major version>.<minor version>.<build number>.<revision> My first piece of general advice is that you don’t keep the two in sync. The assembly version should rather be of the format: <major version>.<minor version>.0.0 The main reason for this is that strong name signatures include the assembly version, which means that if you release an updated assembly, the code that references it will need to be updated too (unless you go the policy route, but let’s keep things simple). The AssemblyFileVersion is the attribute that should be updated with every build you perform, and therein lays the question. How? I would estimate that in 99% of builds, the format of the build number will be <Fixed major version>.<Fixed minor version>.< Calculated build number>.<Iterative revision> The Fixed parts are easy and they will most likely equate to those used in the AssemblyVersion. The calculated part is really up to you. It could be a date format, the number of days since a give milestone etc. The iterative part is where the trouble lies. Let’s look at some tools for versioning. In the past, before TFS, you may have used the SDC Tasks for versioning, or your own bespoke solution. With the first release of TFS, a popular solution was, and still is, the AssemblyInfo Task. All these solutions need to provide the same essential logic. They need to calculate your build number and provide a unique incremental value for every build. To ensure that the incremental value is unique, most versioning solutions check out a file, alter it and check the file back in. This is the operation that causes the most problems. When I first used the AssemblyInfo task, I encountered numerous painful ‘cannot determine the workspace’ errors. I could easily resolve those issues today, but with little experience and understanding of TFS back then, I and many others felt the pain. If that error didn’t catch you, then you were likely to be caught by checkin policies or duplicate attributes. All issues can be resolved, but too many people have had a hard time with this task. So, if you managed to get around the AssemblyInfo task issues, or your own problems with creating a task that checked out a file, incremented the value and then checked it in again, well done... and welcome to contiguous merging issues! TFS 2005 / 2008 don’t support multiple pending merge entries for a single file, so you have to perform contiguous merging. This isn’t a big issue with versioning tasks, however the problem with continuously checking out and in the versioning files(s) is that you get loads of noise on the pending merges table and if you do merge multiple version files, you will likely have to manually resolve the final version. Many people have questioned why Microsoft didn’t release a basic versioning task with TFS, and in fact it appears that the next version of TFS may include such functionality. But why wait? The functionality is already there, it just needs to be used. Don’t do itMy second piece of general advice is don’t check your versioning files in and out during the build process. As discussed above, it creates noise and hassle with merges. As long as you’re versioning logic can be related to the TFS Build Number, I see no benefit in having this source control operation take place. Stop the obsession! The SolutionTFS provides a build number for every build it initiates. The format is <build name>_<year><month><day>.<revision> e.g. MSSDCDaily_20080402.1 To accomplish versioning, use the <revision> part of the build number. TFS will provide an incremented revision for every build, whether the previous build succeeded or not. All you need to do is provide a task that takes the build number as input, then emits your version number as output. The logic within the task is up to you. The lightweight TFS Versioning Tasks provide functionality to easily create builds with a calculated build number in a date or elapsed format. Because your build is based on the build number, you can easily locate the label associated with the build. In summary
I hope that clarifies things...FTD 5月26日 Integrate Microsoft C# Source Analysis with TFSUPDATE - 15 October 2008 : Please see MSBuild Extension Pack for the StyleCop task. UPDATE - 20 July 2008: This task is now available again. This task works with Source Analysis 4.2. A version for StyleCop 4.3 will be made available in the FreeToDev MSBuild Tasks Suite soon... The FTDSourceAnalysis MSBuild task (download here) provides a mechanism for scanning C# files for Source Analysis violations based on a collection of files, rather than the MSBuild integration offered by the tasks provided with the Source Analysis install (which scans @(Compile) items). To use this task, place the FTDSourceAnalysis.dll file in C:\Program Files\MSBuild\Microsoft\SourceAnalysis\v4.2 Sample
Sample Output
This custom collection based scanning provides an easy way to scan various files as part of your TFS builds and flag any violations to the team. 1月25日 Using the TFS Build Number Task with TFS 2008UPDATE: 13 July 08 --- These tasks are now available in the FreeToDev MSBuild Tasks Suite The sample code provided in the blog post covering this light weight task needs to be tweaked if using TFS 2008: TFS 2005:
TFS 2008:
FreeToDev 9月26日 TFS Build Number TasksUPDATE: 13 July 08 --- These tasks are now available in the FreeToDev MSBuild Tasks Suite UPDATE (15 May08): See this post for TFS 2008 support I've added two simple tasks to the FreeToDev.MSBuild.Tasks assembly, both relate to build numbers in TFS. I've previously modified and used the AssemblyInfo task to get assembly versions consistent across all assemblies produced by a team build. I have a few pet hates with regard to this task though.
The following tasks are intended to provide a lightweight and flexible solution to getting your assemblies versioned consistently in a team build.
Team Build Sample<?xml version="1.0" encoding="utf-8"?> Download the latest version with samples here....FTD 8月17日 Getting TFS 2008 functionality in TFS 2005The latest beta of TFS 2008 has a go-live licence and Brian Harry has blogged about the Final TFS 2008 Feature List. TFS 2008 was always marketed as a minor release, targeted at reducing the adoption blockers which have kept companies from buying the product. Anyone who is considering a move to TFS now, should go with TFS 2008. Even if your development is VS2005 based, VS2005 is compatible with TFS 2008. What about all those users out there who have adopted TFS 2005 though? Is it worth upgrading? I think for the majority of TFS 2005 users, the answer will be no. There is already a CTP of Rosario out, and that is the release where in major updates to TFS are being made. I wouldn't be surprised if Rosario ships (in beta with a Go-Live licence) within 12 months of TFS 2008 being launched in February 2008. Skipping TFS 2008 and waiting for Rosario doesn't mean you can't get TFS 2008 features now though. Given the Final TFS 2008 Feature List, I've listed current alternatives you can use now; more may appear in the near future. (I'm still gathering some information, so some features are incomplete, but check back soon for an update. If you know of any better or missing alternatives, please let me know.) Administration, Operations & Setup
Build
Data Warehouse
Migration
Version Control
Work Item Tracking
Web Access
Bug fixes
8月6日 Team Development with Team Foundation Server - GuideOver the last few weeks I've had the opportunity to work with a few people on the Microsoft Patterns and Practices team in writing a guide for TFS. The final version of this guide has now been published and is available here. It's an ideal read for anyone considering TFS or using it today... and buried in the Contributor's list is the identity of FreeToDev... I hope you find the guide useful...FTD. 3月6日 TFS Team Build DropLocationI'm running multiple build servers and want drops to go to the relevant build server rather than a central drop folder. The TFSBuild.proj file has a property called DropLocation that specifies where to drop build output. I decided to add a property to the value of DropLocation to make the build drop locally: <DropLocation>\\$(COMPUTERNAME)\drops\CI---ProductXYZ</DropLocation> Easy enough, but running a build resulted in:
It’s not the $, using %24 gives the ‘same’ message. It looks like the build process is using EvaluatedProperties.Value rather than FinalValue. Luckily there is a way to get around this small bug. I overrode BeforeEndToEndIteration and set DropLocation in there:
If you are wondering what ShowBuildStep is, take a look at this post...FTD 3月1日 It's time to start looking at Orcas...The March CTP is here and I'm looking forward to working with the new bits. Also, check out the great Code Metrics that are included in VS. The Orcas Forums are a great place to request, provide and review feedback...FTD 1月7日 Quick Book Review: Professional Team Foundation ServerI just read Professional Team Foundation Server and thought I'd compile a quick review. If you consider yourself an experienced TFS user, then avoid this book. It's fairly lightweight and tries to cover just about everything in TFS in around 400 pages. If you are a beginner, then go ahead, the book provides an easy read and you can use online resources to further your knowledge in specific areas of the product. One criticism I do have of the book is Chapter 8 'Managing Schemas Using Team Edition for Database Professionals'. What is this chapter doing in a book titled 'Professional Team Foundation Server'? Team Edition for Database Professionals is a great product, and covering it in 25 pages is an injustice. Sticking it in the wrong book is even worse. My Rating:
10月11日 Note To Self: Team Foundation Server Knowledge Base ArticlesI just know I'll be needing something from here some day soon. Check out this great post for Team Foundation Server Knowledge Base Articles |
|
|