Skip to content

Instantly share code, notes, and snippets.

View nvnivs's full-sized avatar

Nuno Pereira nvnivs

View GitHub Profile
@derekgates
derekgates / assemblyinfo_buildnumber.ps1
Last active December 11, 2015 23:18 — forked from drlongnecker/psake task for getting assembly version for TeamCity
TeamCity psake script that sets BuildNumber from an existing AssemblyInfo in source. This is useful as it allows devs to control the version number without needing to change parameters in TeamCity for the project configuration. https://github.com/psake/psake/wiki/How-can-I-integrate-psake-with-Team-City%3F
task default -depends GetBuildNumber
task GetBuildNumber {
Assert ($base_directory -ne $null) '$base_directory should not be null. Try %system.teamcity.build.checkoutDir%'
Assert ($solution_name -ne $null) '$solution_name should not be null'
$version = gc $base_directory\$solution_name\Properties\AssemblyInfo.cs | select-string -pattern "AssemblyVersion" | Out-String
$version | Foreach-Object { Write-Host $_ }
$version -imatch '\[assembly: Assembly(File)?Version\("(?<major>[0-9]+)\.(?<minor>[0-9]+)\.(?<revision>[0-9]+)\.(?<build>[0-9]+)"\)\]' | Out-Null
Assert ($matches -ne $null) 'Unable to find AssemblyVersion string!'