如何在Web部署zip中包含我的配置转换文件?

问题描述 投票:1回答:1

我在Azure Devops中设置新的构建和部署管道。它是一个较旧的Web应用程序,带有一些web.config的转换文件。在过去,我们将根据环境的数量构建相同的代码x次。当我从这里读到https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/transforms-variable-substitution?view=vsts#xmltransform时,这不再是必要的

看起来部署管道可以从我的转换文件中获取更改。

但问题是我的其他转换文件没有包含在包中,因此我收到以下警告消息:

[warning]Unable to apply transformation for the given package. Verify the following.
[warning]1. Whether the Transformation is already applied for the MSBuild generated package during build. If yes, remove the <DependentUpon> tag for each config in the csproj file and rebuild. 
[warning]2. Ensure that the config file and transformation files are present in the same folder inside the package.

当我下载Web工件时,是的。[stage] .config文件不存在建议。

是否有某些设置允许我包含这些文件?还是阻止它们被改造?

azure-devops azure-pipelines azure-pipelines-release-pipeline
1个回答
1
投票

对于Web应用程序

MSBuild知道如何根据以下设置/属性/参数(按顺序)transform the web.config文件

  • 构建配置 dotnet publish --configuration Release
  • 发布个人资料 dotnet publish --configuration Release /p:PublishProfile=FolderProfile
  • 环境 dotnet publish --configuration Release /p:EnvironmentName=Production
  • 自定义文件转换 dotnet publish --configuration Release /p:CustomTransformFileName=custom.transform

我认为开发人员通常只基于构建配置来实现这一点,我相信MSBuild(和dotnet)知道如何基于Web中的<DependentUpon>Web.config</DependentUpon>元素来执行此操作。项目或构建脚本中的[configuration] .config项目文件。

Azure DevOps Release Pipelines有点不同。在构建/发布项目之后,管道想要转换web.config,如果MSBuild(或dotnet)已经尝试过它,则不知道如何做到这一点。从而:

[警告]无法对给定包应用转换。验证以下内容。 [警告] 1。转换是否已在构建期间应用于MSBuild生成的包。如果是,请删除csproj文件中每个配置的标记并重建。 [警告] 2。确保配置文件和转换文件存在于包内的同一文件夹中。

The warning text states:

  1. 删除csproj中每个配置的<DependentUpon>标记 因此:您需要从csproj中删除标记以防止MSBuild转换文件 或者:您需要将/p:TransformWebConfigEnabled=False参数用于MSBuild。 (注意:我认为这是正确的,这可以用于删除依赖标签,但我可能是错的)
  2. 确保转换源文件和目标文件位于包内的同一文件夹中。 可能有几种方法可以做到这一点。我选择将转换源配置文件标记为内容,以强制MSBuild将它们包含在已发布的包中。

现在,您需要根据File Transforms and Value Substitutions文档组织发布管道。

Stage Named According to Desired Transformation

[部分]开始:IIS Web App部署 ==================================== 任务:IIS Web App部署 描述:使用Web Deploy部署网站或Web应用程序 版本:0.0.51 作者:微软公司 帮助:More information ==================================== ... [命令] C:... \ ctt \ ctt.exe s:C:... \ Web.config t:C:... \ Web.Release.config d:C:... \ Web.config pw一世 [命令] C:... \ ctt \ ctt.exe s:C:... \ Web.config t:C:... \ Web.Development.config d:C:... \ Web.config pw一世 XML转换成功应用 ...



对于需要.config转换的非Web应用程序

Getting your .config files to the release pipeline can happen several ways. Here are two.

  1. 您的版本应该作为工件的一部分“访问”存储库,这将确保部署代理下载源(不是理想的IMHO)。
  2. 您需要将web。[stage] .config文件作为构建工件的一部分包含复制任务或拾取它们的迷你匹配。

Once you have the .config files available to the release pipeline

您可以使用XDT Transform任务执行转换操作。


选项2是我走的路线。

以下是该任务对我来说的样子。

enter image description here

该任务将配置放在构建中,然后我可以在发布管道中使用该构建,而无需重建xx次。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.