Building an installer project with NAnt
I finally wrote an NAnt build file for CopySourceAsHtml, put the source into Vault, and put all of the outstanding defects and suggestions into Dragnet. I'd wanted to do this for a long time, but I really wanted the build file to build the installer project, and I really didn't want to use MSITask. Tonight I gave up and used a variant of Scott Hanselman's method. Here's the task:
<target name="build-installer" depends="build">
<attrib file="CopySourceAsHtmlInstaller\CopySourceAsHtmlInstaller.vdproj" readonly="false" />
<script language="C#">
<code>
<![CDATA[
private static string projectFileName = @"CopySourceAsHtmlInstaller\CopySourceAsHtmlInstaller.vdproj";
private static Regex productCodeRegex = new Regex( @"\""ProductCode\"" = \""8:{([\d\w-]+)}\""" );
private static Regex packageCodeRegex = new Regex( @"\""PackageCode\"" = \""8:{([\d\w-]+)}\""" );
private static Regex productVersionRegex = new Regex( @"\""ProductVersion\"" = \""8:(\d+).(\d+).(\d+)\""" );
public static void ScriptMain( Project project )
{
string productVersion;
string projectFilePath;
StreamReader projectFileReader;
string projectFile;
StreamWriter projectFileWriter;
productVersion = project.Properties["product.version"];
projectFilePath = Path.Combine( project.BaseDirectory , projectFileName );
projectFileReader = File.OpenText( projectFilePath );
try
{
projectFile = projectFileReader.ReadToEnd();
}
finally
{
projectFileReader.Close();
}
projectFile = productCodeRegex.Replace( projectFile , "\"ProductCode\" = \"8:{" + Guid.NewGuid().ToString().ToUpper() + "}\"" );
projectFile = packageCodeRegex.Replace( projectFile , "\"PackageCode\" = \"8:{" + Guid.NewGuid().ToString().ToUpper() + "}\"" );
projectFile = productVersionRegex.Replace( projectFile , "\"ProductVersion\" = \"8:" + productVersion + "\"" );
projectFileWriter = new StreamWriter( projectFilePath );
try
{
projectFileWriter.Write( projectFile );
}
finally
{
projectFileWriter.Close();
}
}
]]>
</code>
</script>
<exec program="devenv.exe" commandline="devenv.exe CopySourceAsHtml.sln /rebuild Release /project CopySourceAsHtmlInstaller"/>
</target>
Now that that's done, I'm almost ready to release the new version of CSAH, which will fix some minor defects and some major limitations of the previous versions.
Cheers,
Colin
11:18 PM | Colin

TrackBacks
Comments
# RE: Building an installer project with NAnt
Great job !!!! :) Waiting a lot for the new version...
05:23 PM | Laurent Kempé