【问题标题】:Web.config Transformation during Build构建期间的 Web.config 转换
【发布时间】:2017-01-11 16:27:52
【问题描述】:

我已经在 Visual Studio Team Services 上设置了我的构建,但看起来我的 Web.Release.config 的 Web.config 转换不起作用,我只收到标准的 Web.config。我做错了什么或错过了什么参数。

【问题讨论】:

  • 我从未在 TFS 构建中使用过它,但在 Visual Studio 中,只有在您执行 Deploy 时才会应用转换,当您执行 Build 时创建的配置是未转换的版本。
  • 它运行类似这样的命令 msbuild.exe "myProject.sln" /p:Configuration=Release /p:platform="Any CPU" /p:VisualStudioVersion="15.0"
  • 看到这个问题并回答stackoverflow.com/questions/13920146/…

标签: .net visual-studio azure-devops azure-pipelines


【解决方案1】:

要进行转换,msbuild 需要“部署”解决方案。我不确定最正确的方法,但可以添加一个简单的解决方法

/p:DeployOnBuild=true /p:PublishProfile=SomeProfile

到 MSBuild Arguments 选项。然后,您可以从配置发布配置文件的任何位置获取文件,并在部署期间使用这些文件。

这是一个非常简单的SomeProfile.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 http://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>False</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <publishUrl>$(BUILD_ARTIFACTSTAGINGDIRECTORY)\Release</publishUrl>
    <DeleteExistingFiles>False</DeleteExistingFiles>
  </PropertyGroup>
</Project>

在 TFS 中使用 MSBuild 命令 args

/p:DeployOnBuild=true /p:PublishProfile=SomeProfile

删除/p:outDir

【讨论】:

  • hmm 在我的构建服务器上我不需要发布配置文件,因为复制到 azure 服务器执行 Visual Studio Team Service 的发布管理
  • 也许创建一个配置文件,将转换后的文件放入$(BuildArtifactStagingDirectory)\Release,并在构建步骤中删除/p:outDir。配置文件本身就是 MSBuild 脚本,应该能够使用全局变量。
  • 好的。通过设置它在本地工作的固定路径。如何在配置文件配置中设置 $(BuildArtifactStagingDirectory)?
  • @cpiock 添加了一个应该可以工作的示例 pubxml 文件。只需从 Visual Studio 内部创建一个新配置文件,然后打开 pubxml 文件并根据需要对其进行编辑以获得所需的设置。
【解决方案2】:

配置文件希望在构建服务器上为我工作。我找到了适合我的解决方案。

/p:outdir=$(build.artifactstagingdirectory)\Release /p:UseWPP_CopyWebApplication=true /p:PipelineDependsOnBuild=false

这部分有所不同:

/p:UseWPP_CopyWebApplication=true 

【讨论】:

  • 由于问题是您自己解决的,所以可以标记为答案。
猜你喜欢
  • 1970-01-01
  • 2023-04-02
  • 2013-09-03
  • 1970-01-01
  • 1970-01-01
  • 2020-08-06
  • 2013-01-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多