AssemblyInfo Patcher and customised settings


##teamcity[buildNumber '<buildnum>']

In a powershell script as step 1 of our build configuration we can set the build number and it displays in the web UI. However, this new build number is not reflected in the AssemblyInfo Patcher.

Similarly, setting a custom parameter that can be successfully read off in subsequent build steps does not work in the AssemblyInfo Patcher.

Does the AssemblyInfo Patcher read off all build parameters at the start of the build rather than when it is executing on assemblies? Does it execute on the results of the checkout?How can I force it to run later? I am now using a powershell script build step to accomplish the task.

Comment actions Permalink

Thinking about it more I expect this is by design as the feature in Team City cannot know at what build step my solutions are building, unless it looks for uses of msbuild for example, and reads its parameters just before that step.

I assume the same is true for artifacts path output, with which I have the same issue.

This could be documented?

Comment actions Permalink

So the result here was that Teamcity doesn't support it so I did all this stuff in PowerShell.

Comment actions Permalink

I have the same problem, it almost makes AssemblyInfo Patcher useless for me. Is there a workaround for this. I want to have git short commit hash into my assemblyinfo.

Comment actions Permalink

This is a not-very-elegant script we're using
It does the job

[some imports and params]

$gitVersion = (git describe --tags --long --exact-match) 2>$null
$gitTag = (git rev-parse --abbrev-ref HEAD)

$buildnum = ($buildNumber.Substring(4))
$version = ($gitTag.ToLower()) + "-" + $buildnum.Substring(0,$buildnum.Length-2)

if ($gitVersion) {$version += "-" + ($gitVersion.ToLower())}

Write-Host "##teamcity[setParameter name='swan.buildVersionInfo' value='$version']"

Write-TCHost -message "Updating assembly infos to $version" -type "progressMessage"

$fileVersionPattern = 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$fileVersion = 'AssemblyFileVersion("' + $buildNumber + '")'

$assemblyInformationalVersionPattern = 'AssemblyInformationalVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$assemblyInformationalVersion = 'AssemblyInformationalVersion("' + $version + '")';

# add new attribute to any files that need it

$files = Get-ChildItem .\Src\ -Recurse -Filter AssemblyInfo.cs
$files |
where {
    !((Get-Content $_.fullname) -Match "AssemblyInformationalVersion")
} |
foreach {
    Write-TCHost -message "Adding AssemblyInformationalVersion to - $_.fullname" -type "progressMessage"
    ((Get-Content $_.fullname) + "`r`n[assembly:$assemblyInformationalVersion]") |
    Set-Content -Encoding UTF8 $_.fullname

# edit all files

$files |
foreach {
 Write-TCHost -message "Updating - $_.fullname" -type "progressMessage"

    (Get-Content $_.fullname) |
    foreach {
        % {$_ -replace $assemblyInformationalVersionPattern, $assemblyInformationalVersion } |
        % {$_ -replace $fileVersionPattern, $fileVersion }
    } | Set-Content -Encoding UTF8 $_.fullname

Comment actions Permalink

Hi everybody!

A part of this solution, which I will gladly use, no update from TeamCity team for that? Because as mentioned by William LHeureux, it makes AssemblyInfo Patch useless...


Comment actions Permalink

Dec/2017 and it's still an issue.

Basically the AssemblyInfo Patch feature will put a "File content replacer" step after VCS root update the source code. It will run before any of your build configuration steps so if you update the build number variable in your build step will not affect the original build number that the Assembly Info Patch feature read.



I think we can create a separate build configuration with a single build step just to create a custom build number then make this it as the dependency for the build configuration that has AssemblyInfo patcher. Finally update the build number format to be the dependency build number value


Please sign in to leave a comment.