2

我想使用 Cake 脚本来自动化我的构建和发布过程。我开始使用本地发布进行一些测试,但我无法让我的 Cake 脚本使用我在 Visual Studio 中创建的发布配置文件。有可能吗?

这是我的发布配置文件:

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 <PropertyGroup>
  <WebPublishMethod>FileSystem</WebPublishMethod>
  <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
  <LastUsedPlatform>Any CPU</LastUsedPlatform>
  <SiteUrlToLaunchAfterPublish />
  <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
  <ExcludeApp_Data>False</ExcludeApp_Data>
  <publishUrl>C:\Users\radoslaw.stolarczyk\Desktop\CakeWebSite</publishUrl>
  <DeleteExistingFiles>True</DeleteExistingFiles>
 </PropertyGroup>
</Project>

这是我的蛋糕脚本的两个版本:

  1. 我尝试使用 pubslish 配置文件 (CakeProfile.pubxml) 发布我的网站。它根本不起作用网站被发布到项目文件夹内的文件夹中。

    MSBuild("./CakeWebSite.sln", settings =>
    settings.WithProperty("DeployOnBuild", "true")
    .WithProperty("PublishProfile", "CakeProfile"));
    
  2. 它效果不佳,因此我尝试设置与发布文件中相同的属性:

    MSBuild("./CakeWebSite.sln", new MSBuildSettings()
     .WithProperty("WebPublishMethod", "FileSystem")
     .WithProperty("LastUsedBuildConfiguration", "Debug")
     .WithProperty("LastUsedPlatform", "Any CPU")
     .WithProperty("ExcludeApp_Data", "False")
     .WithProperty("publishUrl", cakePublishPath)
     .WithProperty("OutDir", cakePublishPath)
     .WithProperty("DeleteExistingFiles", "True")
    

第二种选择效果更好,但仍不如预期。Cake 脚本的构建输出与 Visual Studio 发布选项不同,如下图所示:

发布输出

也许这没什么大不了的,例如对于 Cake,我得到了 precompiledApp.config,而对于 Visual Studio,我没有,但我仍然希望从两种发布方法中获得相同的输出。

所以我的问题是:是否可以在 Cake 脚本中使用 Visual Studio 的发布配置文件或接收相同的输出(来自 Cake 和 VS)以及如何?

4

1 回答 1

0

我有下面适合我的配置。我使用项目文件而不是解决方案。

MSBuild(prjFile, new MSBuildSettings()
  .UseToolVersion(MSBuildToolVersion.VS2017)
    .WithTarget("Package")
  .WithProperty("Configuration",configuration)
  .WithProperty("_PackageTempDir", stagingDir)
  .WithProperty("SolutionDir","../")

其中配置是:

var configuration = Argument("configuration", "Release");
于 2018-06-19T16:03:17.603 回答