Building MSI files from NAnt and Updating the VDProj's version information and other sins on Tuesday
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.
Given:
- 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.
Therefore:
- 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#">
<code>CDATA[
public static void ScriptMain(Project project) {
//Shorten the project string (like 1.3.4.5, 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
reader.Close();
}
// create a writer and open the file
TextWriter tw = new StreamWriter(setupFileName);
try {
// write a line of text to the file
tw.WriteLine(file);
} finally {
// close the stream
tw.Close();
}
}
]]>< FONT>code>- Then, I shell out devenv.exe and run my new vdproj with
- 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.
About Newsletter
The reason I ask is that when I shell out devenv.exe to build the .vdproj project, it runs a build of all the assemblies in the solution anyways. I'd rather it didn't, but then I guess it sort of has to unless there's a way to point it to the assemblies in the build output folder.
I used it to change absolute references in my CSS files (tom images and such) when transfering from development to a staging server. What a time (and headache) saver!
I needed to modify the expression to looking for XX.XX.XXXX and any combination there of.
Thanks again.
Along the same lines, you can remove those pesky 'only C#, J#, VB.NET projects supported' errors that show up in your CruiseControl.NET logs as warnings if you do something along these lines:
http://dotnetbkm.blogspot.com/2005/11/nant-solution-task-and-setupmerge.html
Cheers,
John
Comments are closed.
BTW, whatever dasBlog is doing to create emoticons is having fun with your regexes.