1

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
4

2 回答 2

1

也许不推荐的方式,但如果您在构建代理上有 VisualStudio,您可以利用它来使用 VisualStudio 命令行开关构建安装程序。

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

Cake 中没有用于 VisualStudio 命令行 ( ) 的内置别名devenv.com,但您可以只启动该进程,或者像我下面的示例中那样劫持MSBuild别名。

示例项目

示例项目将有一个名为“TheApp”的应用程序和一个名为“TheInstaller”的安装程序,如下所示:

示例项目根目录

构建蛋糕

我创建了一个最小的蛋糕脚本,只是演示了如何首先使用 MSBuild 构建项目,然后使用 VisualStudio 进行安装。通常你会有清理/nuget恢复等任务。

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/项目文件的路径
  • 配置是构建的配置,即发布/调试。

示例输出

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

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
于 2016-09-21T22:19:15.783 回答
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)来构建项目

这取决于您如何进行,但是,就个人而言,我不喜欢第二种选择。

于 2016-09-18T19:25:35.057 回答