RSS Feed

Tuesday, August 19, 2008

NAnt and Setup Projects (*.vdproj)

If you're like me, you're lazy. And last night, while on my couch watching the Olympics, I attempted to do a simple thing - compile a solution containing a setup project (.vdproj) from NAnt. After all, when you're distributing a Windows Forms application to a non-technical audience, it's natural to want an installer to bootstrap to the .NET framework, copy the application to the program files directory, and create an icon on the desktop and start menu. To enhance efficiency through automation, it's also natural to want to build the software on a build server instead of manually on a developer workstation. Let's just say it took longer than a few heats of the 100m butterfly to complete this simple task. Hopefully I can decrease that learning curve for you, my fellow developer.

My first thought was, "I'll use msbuild to compile the solution". It's completely logical, but unfortunately impossible. vdproj files can only be compiled by Visual Studio. After about an hour of scouring the Internet in denial and throwing up in my bathroom, I accepted this *enormous* limitation. Apparently this issue has been known by Microsoft since at least 2004, but they haven't had time to address it. Most likely this time was instead spent pursuing the Microsoft dream. By the way, in the Microsoft dream a non-technical website administrator drags their entire SQL Server database onto the ASP.NET "design surface" and selects the publish option from the build menu.

The next problem that arises is: how do I call Visual Studio from NAnt? What executable and command-line arguments do I use? How do I dynamically determine where Visual Studio is installed? Below is some NAnt code that answers these questions:

<readregistry
property="ide.dir"
key="SOFTWARE\Microsoft\VisualStudio\9.0\InstallDir"
hive="LocalMachine" />

<
echo message="IDE Directory is ${ide.dir}" />

<
exec
program="devenv.exe"
workingdir="."
basedir="${ide.dir}"
commandline="src\XYZ.sln /Clean"/>

<
exec
program="devenv.exe"
workingdir="."
basedir="${ide.dir}"
commandline="src\XYZ.sln /Rebuild Release"/>

There are a couple of ways of skinning this cat, but reading the Visual Studio 2008 path out of the registry actually turns out to be the simplest solution. I hope this helps somebody else out some day.

9 comments:

Neil Mosafi said...

Cor blimey! We use wix for this sort of stuff...

Anonymous said...

neil, got any links to help for bootstrapping .net with wix?

Pero said...

Look at Wix Tutorial.

Regards, Petar

Brian Sullivan said...

Love the description of the "Microsoft dream!" Hilarious!

Anonymous said...

By the way, in the Microsoft dream a non-technical website administrator drags their entire SQL Server database onto the ASP.NET "design surface" and selects the publish option from the build menu.

And this will work… as long as said non-technical website administrator only wants to use the provided controls in exactly the way they are provided. Any deviation will require a new object developed from scratch.

Regards CJ

Ahr Family said...

the only thing that would make this blog more useful is if was added to more often than once every few months

Beulah said...

Keep up the good work.

Marcin Rybacki said...

You post saved my day, thanks! :)

mcraig88 said...

In my experience, devenv alway returns a code of 1 which causes nant to fail. Have you experienced this? I have set my <exec failonerror='false'> to get past this. Any suggestions?