如何使用可视化发布配置文件和Cake脚本部署网站

时间:2018-03-21 14:52:12

标签: msbuild webdeploy cakebuild pubxml

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

这是我的发布个人资料文件:

$string_replaced = str_replace($string_btwn_parenthesis," ",$string);

$arrayfields = explode(",",$string_replaced);

以下是我的蛋糕脚本的两个版本:

  1. 我尝试使用pubslish个人资料(CakeProfile.pubxml)发布我的网站。它不能在所有网站上发布到项目文件夹内的文件夹。

    <?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>
    
  2. 它没有用,所以我尝试设置与发布文件相同的属性:

    MSBuild("./CakeWebSite.sln", settings =>
    settings.WithProperty("DeployOnBuild", "true")
    .WithProperty("PublishProfile", "CakeProfile"));
    
  3. 第二种选择效果更好但仍未达到预期效果。 Cake脚本的构建输出与Visual Studio发布选项不同,如下图所示:

    Publish outputs

    也许这对于Cake来说并不是什么大问题我得到了precompiledApp.config和Visual Studio我不会但是我仍希望从两种发布方法中获得相同的输出。

    所以我的问题是:是否可以在Cake脚本中使用Visual Studio中的发布配置文件或者从Cake和VS中获取相同的输出以及如何?

1 个答案:

答案 0 :(得分:0)

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

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

其中的配置是:

var configuration = Argument("configuration", "Release");