.Net application builds and versions using bamboo

I have a .net project that i am already using MSbuild for and i have that working great. My question is i would like to be able to save each version and actually version my application on each build using bamboo. Then we have a dev/test/prod server that i would like to be able to push any version to any server at anytime.. now i see references for these sort of things but i cant seem to find any good information on how to make this all happen. Can someone point me in a direction for this?


1 answer

We used to do this with CruiseControl.net but decided not to with bamboo.

It is an old powershell script but it worked fine. You'd need to pass in the parameters from Bamboo as arguments to the script or use them inline in the new script command running as powershell.

function SetVersion ($file)
	$version = $ENV:CCNetLabel
	$svn_rev = ([int] $version.Split('.')[3])
	$mod_svn_rev = $svn_rev % 10000
	$version = $version.Replace("$svn_rev","$mod_svn_rev")
	$fileObject = get-item $file

	"Changing version in $file to $version"

	$sr = new-object System.IO.StreamReader( $file, [System.Text.Encoding]::GetEncoding("utf-8") ) 
	$content = $sr.ReadToEnd()

	$content = [Regex]::Replace($content, "(\d+)\.(\d+)\.(\d+)\.(\d+)", $version);

	$sw = new-object System.IO.StreamWriter( $file, $false, [System.Text.Encoding]::GetEncoding("utf-8") )
	$sw.Write( $content )

# Set the Assembly version
$info_files = Get-ChildItem .\ -Recurse -Include "AssemblyInfo.cs" | where {$_ -notmatch 'A3Domain'}
foreach($file in $info_files)
	Setversion $file		

Our labels ($ENV:CCNetLabel) were already a 3 piece release version then we tacked on a piece of the revision. Mod by 10000 was a quick hack to avoid unsigned __int16 overflow, it can produce non sequential versions though so I'd try to avoid it.

Basically the idea is to change the AssemblyInfo.cs BEFORE the build.

I used this as a template with minor modifications and it works fine.

My only complaint is that it has to be checked into the repo to work, it would be nice to have it as a task type

I replaced your code at the top up to the point where your version is modified with this

function SetVersion ($file, $version)

changed your calling line to this

Setversion $file $versionNew

 And then created a script task in bamboo, setting Run as Powershell script with this as the body

.\ChangeAssemblyInfo.ps1 -version 0.1.${bamboo.buildNumber}.0


you can put the whole script into the bamboo task, but that hurt my sensibilities.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Monday in Jira Ops

Jira Ops Early Access Program Update #1: Announcing our next feature and a new integration

Thanks for signing up for Jira Ops! I’m Matt Ryall, leader for the Jira Ops product team at Atlassian. Since this is a brand new product, we’ll be delivering improvements quickly and sharing updates...

509 views 0 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you