Inedo Community Forums Forums
    • Recent
    • Tags
    • Popular
    • Login

    Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.

    If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!

    Why the task 'Write Assembly Version' does not take revision as part of version?

    Scheduled Pinned Locked Moved Support
    buildmaster
    3 Posts 2 Posters 4 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ? This user is from outside of this forum
      Guest
      last edited by

      Following is the excerpt from any standard Assembly info file.

      // Version information for an Solution consists of the following four values:
      //
      //      Major Version
      //      Minor Version 
      //      Build Number
      //      Revision
      //
      // You can specify all the values or you can default the Revision and Build Numbers 
      // by using the '*' as shown below:
      
      [assembly: AssemblyVersion("2.14.6878.*")]
      

      If we specify value for version parameter on 'Write Assembly Version' task with revision (e.g. above "2.14.6878.*" so that the revision number is generated automatically by Ms build), the task results in error 'The Specified version is 2.14.6878.* not a valid'

      We can successfully build our source code outside build master with this value in AssmeblyInfo.cs.

      Build master would be fine with version parameter value '2.14.6878' and the resultant assemblies would have version '2.14.6878.0'. Thus the revision part of the Assembly version would be always 0.

      Is there way to get around this?

      Product: BuildMaster
      Version: 6.0.11

      1 Reply Last reply Reply Quote 0
      • J Offline
        jharbison
        last edited by

        The WriteAssemblyInfoVersions operation is part of Inedo's WindowsSDK extension. They have all of their extensions hosted open source on GitHub. You can see here that this operation is using the System.Version constructor. The documentation notes that a FormatException will be thrown if any component of the version does not parse to an integer so specifying '*' as the revision explains the error you are seeing.

        As for how to get an incrementing revision number, usually this would be your $PackageNumber. By default if you don't specify a version to the operation it will fallback to $ReleaseNumber.$PackageNumber. For a brand new release with a single package this would look like 0.0.0.1 by default. However, if you are perhaps redeploying a package multiple times and need to distinguish between them you could use the $ExecutionId.

        1 Reply Last reply Reply Quote 0
        • ? This user is from outside of this forum
          Guest
          last edited by

          Thanks Josh for the response.
          I ended up using custom Power shell task.

          <#
          .SYNOPSIS
          Script to set assembly version for dot net assmeblies.
          
          .PARAMETERS
          .sourceFolder
          folder where the source is located.
          
          .newVersion
          
          .assemblyInfoFileNamePattern
          name of assembly info file 
          #>
          param(    
              [string]$sourceFolder,
              [string]$newVersion,
              [string]$assemblyInfoFileNamePattern
          )
          
          if( [string]::IsNullOrEmpty($assemblyInfoFileNamePattern)){
                  $assemblyInfoFileNamePattern = "*AssemblyInfo*.*"
          }
          
          if( [string]::IsNullOrEmpty($newVersion)){
                  $newVersion = "1.0.0.0"
          }
          
          $versionSplit =  $newVersion.Split(".")
          
          if($versionSplit.Length -eq 2){
              $newVersion = $newVersion + ".*.*"
          }
          
          if($versionSplit.Length -eq 3){
              $newVersion = $newVersion + ".*"
          }
          
          
          ################################################################################## 
          # Output execution parameters. 
          "Executing with the following parameters:" 
          "  source Folder: $sourceFolder" 
          "  new Version: $newVersion" 
          "  assembly Info File Name Pattern: $assemblyInfoFileNamePattern" 
          ##################################################################################     
          
          $pattern = '\[assembly: AssemblyVersion\("(.*)"\)\]'
          
          Get-ChildItem -Path $sourceFolder -Filter $assemblyInfoFileNamePattern -Recurse | ForEach{
              "found file " + $_.FullName
              $fileFound = $_
              (Get-Content $fileFound.FullName) | ForEach-Object{
              if($_ -match $pattern){
                  # We have found the matching line
                  # Edit the version number and put back.
                  #$fileVersion = [version]$matches[1]
                  #$targetVersion = "{0}.{1}.{2}.{3}" -f $fileVersion.Major, $fileVersion.Minor, $fileVersion.Build, ($fileVersion.Revision + 1)
                  '[assembly: AssemblyVersion("{0}")]' -f $newVersion
              } else {
                  # Output line as is
                  $_
              }
          } | Set-Content $fileFound.FullName -Force
          
          }
          
          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • 1 / 1
          • First post
            Last post
          Inedo Website Home • Support Home • Code of Conduct • Forums Guide • Documentation