Scott Hanselman

Building MSI files from NAnt and Updating the VDProj's version information and other sins on Tuesday

March 30, 2004 Comment on this post [0] Posted in NUnit | Nant
Sponsored By

So, I commited a series of mortal sins today, but hey, it works, right? :)  Other people have felt my pain, so I thought I'd share.

We have a glorious automated build process with NAnt and NUnit and CruiseControl.  We also update all the AssemblyInfo files (we actually create 'AssemblyVersion.cs' files).  We zip up all the binaries and NDoc generated CHM files.

Additionally I want to create an MSI file at the end of it all. 


  • I don't want to mess with Installshield yet as the VS.NET stuff does what I need for now. 
  • I don't want to mess with the msitask because it's too freaky.


  • I update the versions inside of the setup.vdproj myself with some of the worse regex's and crappiest code I've done in the last month.

    <target name="updatemsisetupversion" depends="setup">
    <property name="short.project.version" value="0.0.0" />
    <script language="C#">
    public static void ScriptMain
    (Project project) {
    //Shorten the project string
    (like, to 1.3.4)
    string projectVersion = project.Properties["project.version"];
    projectVersion = projectVersion.Substring(0,projectVersion.LastIndexOf("."));
    project.Properties["short.project.version"] = projectVersion;
    string setupFileName = Path.Combine(project.BaseDirectory, "setup\\MySetup.vdproj");
    StreamReader reader = File.OpenText(setupFileName);
    string file = String.Empty;
    try {
    Regex expression1 = new Regex(@"(?:\""ProductName\"" = \""8.My Project  )(\d.\d.\d+)");
    Regex expression2 = new Regex(@"(?:\""ProductCode\"" = \""8.){([\d\w-]+)}");
    Regex expression3 = new Regex(@"(?:\""PackageCode\"" = \""8.){([\d\w-]+)}");
    Regex expression4 = new Regex(@"(?:\""ProductVersion\"" = \""8.)(\d.\d.\d+)");
    file = reader.ReadToEnd();
    file = expression1.Replace(file,"\"ProductName\" = \"8:My Project " + projectVersion);
    file = expression2.Replace(file,"\"ProductCode\" = \"8:{" + Guid.NewGuid().ToString().ToUpper() + "}");
    file = expression3.Replace(file,"\"PackageCode\" = \"8:{" + Guid.NewGuid().ToString().ToUpper() + "}");
    file = expression4.Replace(file,"\"ProductVersion\" = \"8:" + projectVersion);
    finally {
    must remember to close the file or the compile may not work
    create a writer and open the file
    TextWriter tw = new StreamWriter(setupFileName);
    try {
    // write a line of text to the file
    finally {
    close the stream

  • Then, I shell out devenv.exe and run my new vdproj with

Note: YES, I know the RegEx's suck, and I'm loading the file into a single string, and blah blah blah, micro perf, optimizations, etc.  But, it's a build file. so Nyah! :P 

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.