Monday, May 07, 2007

Updating assembly version with the CI build: better code

Just an update for a previous post (it's too long to publish it in the same article). As I mentioned, the use of C# script will eliminate disadvantage of using <asminfo> task and give cleaner and more robust solution. So here is the code:

  <target name="update-assembly" description="Replaces the version in the assemblyinfo.cs file">
<script language="C#">
<code>
<![CDATA[
public static void ScriptMain(Project project)
{
string fileContent="";
using (StreamReader reader = new StreamReader(project.Properties["info.file"]))
{
fileContent= reader.ReadToEnd();
reader.Close();
}
string newVersion = string.Format("[assembly: AssemblyVersion(\"{0}\")]",
project.Properties["buildnumber.version"]);
string newText = Regex.Replace(fileContent, @"\[assembly: AssemblyVersion\("".*""\)\]", newVersion);
using (StreamWriter writer = new StreamWriter(project.Properties["info.file"], false))
{
writer.Write(newText);
writer.Close();
}
}
]]>
</code>
</script>
</target>

No comments:


© 2008-2013 Michael Goldobin. All rights reserved