如何使用cake MSBuild构建Visual Studio Installer .vdproj?

时间:2016-09-18 14:31:32

标签: c# msbuild cakebuild

build.cake是这样的:

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

xxx.sln包含xxx_Setup.vdproj,但在运行时它不会构建

.\build.ps1 -Target Build

2 个答案:

答案 0 :(得分:1)

基于这个讨论,它会出现:

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

MSBuild不支持构建vdproj文件。相反,这是Visual Studio知道如何做的事情,而不是MSBuild,

此博客文章进一步支持了这一点:

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

两种情况下建议的解决方法是:

  • 转向其他包装技术,例如WiX。
  • 直接调用Visual Studio(即devenv.exe)来构建项目

由您决定如何继续,但是,就个人而言,我不喜欢第二种选择。

答案 1 :(得分:1)

也许不推荐使用方法,但如果在构建代理上安装了VisualStudio,则可以使用VisualStudio命令行开关来构建安装程序。

要构建安装程序,首先构建应用程序,然后安装程序或者很可能会遇到运行时错误,这一点非常重要。

在VisualStudio命令行(devenv.com)的Cake中没有内置别名,但您可以启动该过程,或者在下面的示例中劫持MSBuild别名。< / p>

示例项目

示例项目将有一个名为&#34; TheApp&#34;和一个名为&#34; TheInstaller&#34;像这样:

example project root

build.cake

我创建了一个最小的蛋糕脚本,只演示如何首先使用MSBuild构建项目,然后使用VisualStudio安装程序。通常,您将完成清理/修复等任务。

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是devenv.com(位于devenv.exe)
  • solutionPath是解决方案文件的路径
  • appProjectPath是应用程序csproj /项目文件的路径
  • 配置是要构建的配置,即Release / Debug。

示例输出

如果一切顺利,您应该看到类似于下面的构建日志

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