.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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Friday in Bitbucket

What is your #1 piece of advice to new users getting started using Bitbucket?

Hello Community! My name is Claire Maynard, and I’m a Product Marketing Manager on the Bitbucket team. I’m interested in hearing what advice or tips you have for new users getting started on ...

126 views 5 2
Join discussion

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