views:

132

answers:

1

Hi

I have a NAnt script that compiles our web application, but would like to programatically update the version number of the assembly it generates. I have sourced the version numbers already and you can assume they have been stored in some NAnt variables.

Can figure out how to do this for standard projects, but not for web deployment projects.

Any help you can provide would be appreciated.

Thanks in advance!

+2  A: 

You have to write the version number into the web deployment project file itself. This NAnt task should do it:

  <target name="setAssemblyVersion" description="Increments/Sets the AssemblyVersion value" depends="getAssemblyVersion">
    <foreach item="File" property="filename">
      <in>
        <items>
          <include name="**/*.wdproj"></include>
        </items>
      </in>
      <do>
        <script language="C#">
          <code>
            <![CDATA[
           public static void ScriptMain(Project project) {
               string contents = "";
               StreamReader reader = new StreamReader(project.Properties["filename"]);
               contents = reader.ReadToEnd();
               reader.Close();
               string replacement = string.Format(
                   "<Value>{0}.{1}.{2}.{3}</Value>",
                   project.Properties["build.major"],
                   project.Properties["build.minor"],
                   project.Properties["build.build"],
                   project.Properties["svn.revision"]
               );  

               string newText = Regex.Replace(contents, @"<Value>([0-9]+\.){3}[0-9]+</Value>", replacement);
               StreamWriter writer = new StreamWriter(project.Properties["filename"], false, Encoding.UTF8);
               writer.Write(newText);
               writer.Close();
           }        
           ]]>
          </code>
        </script>
      </do>
    </foreach>
  </target>

I'm guessing your NAnt property names...

David M
Perfect! Thank you very much!
MPritch
You're welcome.
David M