也许不推荐的方式,但如果您在构建代理上有 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