Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

.Net application builds and versions using bamboo

Kevin Holy November 12, 2013

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?

Thanks!

1 answer

1 vote
Jason Monsorno
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 12, 2013

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
	$fileObject.Set_IsReadOnly($False)

	"Changing version in $file to $version"

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

	$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 )
	$sw.Close()
	$fileObject.Set_IsReadOnly($True)
}

# 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.

Matthew Lyon July 28, 2016

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

param([string]$versionNew)
 
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

Correction:

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
TAGS
AUG Leaders

Atlassian Community Events