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#">
public static void ScriptMain(Project project)
string fileContent="";
using (StreamReader reader = new StreamReader(project.Properties["info.file"]))
fileContent= reader.ReadToEnd();
string newVersion = string.Format("[assembly: AssemblyVersion(\"{0}\")]",
string newText = Regex.Replace(fileContent, @"\[assembly: AssemblyVersion\("".*""\)\]", newVersion);
using (StreamWriter writer = new StreamWriter(project.Properties["info.file"], false))

No comments:

© 2008-2013 Michael Goldobin. All rights reserved