• Anthony Stevens

How To Build .vdproj Files In MSBuild

Software

It’s somewhat amazing to me that in 2010 there should still be any problems or confusion surrounding how to build Windows Installer (.vdproj) projects in MSBuild.  But, as Edna Mode says, “Yet here we are, darling.”

First problem: figuring out the syntax.  Well that was the first, last, and in-between problem, but when I typed the following into PowerShell:

devenv.exe /?

I got Visual Studio to fire up and show a message box with some command-line help.  Unfortunately, the version of Visual Studio was 2005, not 2008 as I might have expected.  Turns out my $env:path environment variable was riddled with references to *Microsoft Visual Studio 8* when really I wanted *Microsoft Visual Studio 9.0*.

OK, I can fix that temporarily by navigating to:

c:\program files\microsoft visual studio 9.0\common7\ide

And re-running the command

devenv.exe /?

Yet I still got the IDE to open up with a message box full of command-line and switch information.

Aha! I thought.  Perhaps I need to run the .com version of the program, not the .exe.  I am operating in a command-line environment, after all.

Changing to:

devenv.com /?

Showed me an inline help list which matched the IDE message box, but at least I’m operating within PowerShell 100% now.

OK, so about the format of the command line to build a VDPROJ setup project.  At first I thought that it would be something simple like:

<Exec Command=”$(DevEnv) $(ProjectFile) /Build ‘Debug’”/>

Where $(DevEnv) was the path to devenv.com and $(ProjectFile) was the path to my .vdproj file.  Well, two problems.  First was the single- vs. double-quoting issue.  The Exec task’s Command attribute takes a quoted string.  It turns out you have to use XHTML &quot; pseudo-characters to delineate the arguments.

The second problem was more subtle.  As it turns out, you have to pass in the SOLUTION file first, then you have to tell devenv what PROJECT FILE you want built.  Very counter-intuitive.

Here’s my final target in my .msbuild file:

<Target Name="Foo">
        <PropertyGroup>
            <DevEnv>$(ProgramFiles)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.com</DevEnv>
            <SolutionFile>$(MSBuildProjectDirectory)\MySolution.sln</SolutionFile>
            <ProjectFile>$(MSBuildProjectDirectory)\MySetupProject\MySetup.vdproj</ProjectFile>
            <Configuration>Debug</Configuration>
        </PropertyGroup>
        <Exec
                Command="&quot;$(DevEnv)&quot; &quot;$(SolutionFile)&quot; /Rebuild &quot;$(Configuration)&quot; /Project &quot;$(ProjectFile)&quot; /ProjectConfig &quot;$(Configuration)&quot; /Log"
                ContinueOnError="false"
                IgnoreExitCode="false"
                WorkingDirectory="$(MSBuildProjectDirectory)" />
    </Target>

I still have to do some work to do a clean prior to the rebuild, and I’m not sure why the configuration needs to be specified twice, but this has gotten me working this weekend. Hope this helps some of you out.

9 Comments

9 Comments

  1. Martin Maat  •  May 8, 2010 @7:52 am

    You should remove MSBuild from the title of your article. Lots of people would like to build setup projects using MSBuild yet this is still impossible. You are just telling them how to do it with Visual Studio. We knew how to do that. So this article is just a big disappointment to anyone who finds it.

  2. Robert Schroeder  •  May 10, 2010 @8:40 am

    I disagree Martin — helped me find exactly what I was looking for – Thanks for the post.

  3. Michael Go  •  Jul 7, 2010 @3:13 pm

    Martin was right. I’m disappointed. I need to build with MSBUILD without Visual Studio in the picture.

  4. Alessandro Riolo  •  Jul 30, 2010 @8:45 am

    I have also used devenv.exe with the documented switches, and it works as well.

  5. Crispin Wright  •  Aug 4, 2010 @2:27 am

    Martin Maat is bang on the money here unfortunately.

    You are not using MSBuild to build the project.

    You are requiring a Visual Studio installation be on the box, and you are using devenv.

    Your article is sorely mistitled.

  6. Pat K.  •  Jan 7, 2011 @5:22 am

    The title is a little misleading, but still got me here. I
    was looking for a way around this also, as for some glaringly-wrong
    reason M$ decided not to have MSBuild support vdproj files and it’s
    been like that for well several Visual Studio releases. Seeing as
    we cannot use the standard build, this might at least be a
    workaround? And may just be a more elegant solution than say
    CruiseControl, though WiX looks promising?

  7. Jeff  •  Jan 21, 2011 @10:19 am

    Thanks for the help!

    It may not satisfy some people’s needs, but it certainly satisfied mine. I got here easily and found just the information I needed. I had to adjust the command-line a little to get it to work for me.

  8. espinete  •  Jul 19, 2011 @11:20 am

    Great !!!
    samples in MsBuild, PowerShell , Wix is required…

    perhaps AllOneCode Script in codeplex like all1code.codeplex.com

    thx

  9. Namit  •  Nov 2, 2011 @1:11 am

    This is what I was looking for. To build .vdproj Files using command line.
    I had Visual Studio 2005, and was wondering whether this will still work. And it worked! Thanks!