【问题标题】:How to build Visual Studio Installer .vdproj with cake MSBuild?如何使用 cake MSBuild 构建 Visual Studio Installer .vdproj?
【发布时间】:2016-09-22 06:19:15
【问题描述】:

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

【问题讨论】:

  • 如果启用详细诊断,如下所述:stackoverflow.com/questions/38658660/… 实际执行的 msbuild 命令是什么?这与构建该项目的 msbuild 命令有何不同?
  • 日志显示此解决方案中的其他项目已构建,但安装程序项目除外。似乎 MSBuild 无法构建 vdproj。
  • 电脑上是否安装了构建vdproj文件的工具?
  • 您需要在计算机上安装 Visual Studio 并安装此 vsix 扩展:visualstudiogallery.msdn.microsoft.com/…
  • 是的,我已经安装了它,并且可以在从 IDE 构建解决方案的同时构建 MSI

标签: c# msbuild cakebuild


【解决方案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)来构建项目

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

【讨论】:

    【解决方案2】:

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

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

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

    示例项目

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

    build.cake

    我创建了一个最小的蛋糕脚本,只是演示了如何首先使用 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
    

    【讨论】:

    • Visual Studio 安装程序项目似乎将被弃用,所以无论如何都会使用 WiX。
    猜你喜欢
    • 2012-03-11
    • 1970-01-01
    • 2017-08-10
    • 2016-10-09
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    相关资源
    最近更新 更多