Ask A Question

View Question

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

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.

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

}
Answer Question