Versioning .NET builds

后端 未结 8 1400
萌比男神i
萌比男神i 2020-12-14 22:27

Just wondering what\'s the best approach to versioning of .NET builds?

I use:

  • TFS 2013 for version control
  • TFS gated check-ins
  • Wix 3.
8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-14 22:40

    I came up with a solution that meets all my requirements, and surprisingly quite simple one!

    IDEA

    Put all custom Versioning work into a custom Version.proj MsBuild script and call it in TFS build definition before the .sln. The script injects Version into source code (SharedAssemblyInfo.cs, Wix code, readme.txt), and then solution build builds that source code.

    Version is formed from Major and Minor numbers living in Version.xml file stored in TFS together with the source codes; and from Changeset Number supplied as TF_BUILD_SOURCEGETVERSION env var by parent TFS Build process

    enter image description here

    Thanks Microsoft for this:

    • TFS 2013 - passes TF_BUILD environment variables to the build process, this is how I get changeset number of the current code being built
    • MsBuild allows inline tasks in C# - to replace version in source files using Regex C# class

    So there is no need to use any MsBuild or TFS community\extension packs\addons\whatever. And there is no need to modify standard TFS build process template. Simple solution leads to high maintainability!

    IMPLEMENTATION

    Version.proj

    
    
    
    
    
      
        ..\Version.xml
        ... set this to main solution directory ...
      
    
      
      
    
      
        
        
    
        
        
      
    
    
      
        
        
      
    
    
      
        
            $(MajorVersion).$(MinorVersion).$(TF_BUILD_SOURCEGETVERSION.Substring(1))
        
        
      
    
    
      
        
            
            
                (?<=\[assembly:\s*Assembly?Version\(["'])(\d+\.){2,3}\d+(?=["']\)\])
                $(FullVersion)
            
            
                (?<=\[assembly:\s*AssemblyFileVersion\(["'])(\d+\.){2,3}\d+(?=["']\)\])
                $(FullVersion)
            
            
                (?<=<\?define\s+ProductVersion\s*=\s*['"])(\d+\.){2,3}\d+(?=["']\s*\?>)
                $(FullVersion)
            
        
    
        
        
        
      
    
    
    
      
        
        
      
    
      
        
        
        
        
        
      
    
    
    

    Common.proj

    
    
      
        
          
          
          
        
        
          
          
          
          
          
        
      
    
      
        
      
    
    

    Version.xml

    
    
      
        1
        1
      
    
    

提交回复
热议问题