简体   繁体   中英

How to build Visual Studio Installer .vdproj with cake MSBuild?

The build.cake is like this:

Task("Build")
  .Does(() =>
{
  MSBuild("./xxx.sln", new MSBuildSettings {
    Verbosity = Verbosity.Minimal,
    ToolVersion = MSBuildToolVersion.VS2015,
    Configuration = "Release",
  });
});

The xxx.sln contains xxx_Setup.vdproj, but it doesn't get built when I run

.\build.ps1 -Target Build

It would appear, based on this discussion:

http://help.appveyor.com/discussions/problems/626-added-a-visual-studio-install-project-and-now-and-getting-errors-during-build

That MSBuild does not support the building of vdproj files. Instead, this is something that Visual Studio knows how to do, but not MSBuild,

This is further backed up by this blog post:

http://techproblemssolved.blogspot.co.uk/2009/05/msbuild-and-vdproj-files.html

The suggested workaround in both cases is either:

  • Move to another packaging technology, such as WiX.
  • Invoke Visual Studio directly (ie devenv.exe) to build the project

It is up to you how you proceed, however, personally, I don't like the second option.

Perhaps not recommended way but if you have VisualStudio on the build agent you can utilize that to build the installer using the VisualStudio Command Line Switches.

To build installer it's important that you build app first, then the installer or you most likely will run into runtime errors.

There's no built in alias in Cake for the VisualStudio command line ( devenv.com ), but you could just launch the process or as in my example below hijack the MSBuild alias.

Example project

The example project will have an application called "TheApp" and an installer called "TheInstaller" like this:

示例项目根

build.cake

I've created a minimal cake script just demonstrate how to first build project with MSBuild and then installer with VisualStudio. Normally you'll have tasks for clean/nuget restore etc.

FilePath vsToolPath     = "C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/devenv.com";
FilePath solutionPath   = "./InstallerTest.sln";
FilePath appProjectPath = " ./TheApp/TheApp.csproj";
string configuration    = "Release";


Task("Build")
  .Does(() =>
{
  // Build project
  MSBuild(appProjectPath, new MSBuildSettings {
    Verbosity = Verbosity.Minimal,
    Configuration = configuration
    });

  // Build installer
  MSBuild(solutionPath, new MSBuildSettings {
    ToolPath = vsToolPath,
    ArgumentCustomization = args=>new ProcessArgumentBuilder()
                                .AppendQuoted(solutionPath.FullPath)
                                .Append("/build")
                                .Append(configuration)
                                .Append("/project")
                                .Append("TheInstaller")
  });
});

RunTarget("Build");
  • vsToolPath is that to devenv.com (located along devenv.exe)
  • solutionPath is the path to solution file
  • appProjectPath is the path to application csproj/project file
  • configuration is the configuration to build ie Release / Debug.

example output

If all goes well you should see a build log similar to below

C:\InstallerTest> cake .\build.cake

========================================
Build
========================================
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.

  TheApp -> C:\InstallerTest\TheApp\bin\Release\TheApp.exe

Microsoft Visual Studio 2015 Version 14.0.25420.1.
Copyright (C) Microsoft Corp. All rights reserved.
------ Starting pre-build validation for project 'TheInstaller' ------
------ Pre-build validation for project 'TheInstaller' completed ------
1>------ Build started: Project: TheInstaller, Configuration: Release ------
Building file 'C:\InstallerTest\TheInstaller\Release\TheInstaller.msi'...
========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

Task                          Duration
--------------------------------------------------
Build                         00:00:06.2353275
--------------------------------------------------
Total:                        00:00:06.2353275

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM