如何在Web部署zip中包含我的配置转换文件? [英] How to include my config transformation files in the web deploy zip?

查看:86
本文介绍了如何在Web部署zip中包含我的配置转换文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Azure Devops中建立了一个新的生成和部署管道.它是一个较旧的Web应用程序,其中包含一些用于web.config的转换文件.过去,我们会根据多少个环境来构建相同的代码x次.正如我从这里 https://docs.microsoft.com/zh-cn/azure/devops/pipelines/tasks/transforms-variable-substitution?view=vsts#xmltransform

Im setting up a new build and deploy pipeline in Azure Devops. It is an older Web application with some transformation files for the web.config. In the old days we would build the same code x times depending on how many environments. This this is no longer necesary as I read from here https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/transforms-variable-substitution?view=vsts#xmltransform

部署管道似乎可以从我的转换文件中获取更改.

it looks like the deploy pipeline can pick up the changes from my transform file.

但是问题是我的其他转换文件没有包含在软件包中,所以我得到了以下警告消息:

But the problem is that my other transform files does not get included in the package so I get these warning message:

[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文件不存在建议的

And yes when i download the artifact the Web.[stage].config files are not there as suggested.

在某些地方可以让我包含这些文件的设置吗?还是阻止他们转型?

Is there some setting somewhere that let me include these files? Or stop them from being transformed?

推荐答案

对于Web应用程序

MSBuild知道如何根据以下设置/属性/参数(按顺序)转换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
  • Build Configuration
    dotnet publish --configuration Release
  • Publish profile
    dotnet publish --configuration Release /p:PublishProfile=FolderProfile
  • Environment
    dotnet publish --configuration Release /p:EnvironmentName=Production
  • Custom file transform
    dotnet publish --configuration Release /p:CustomTransformFileName=custom.transform

我认为对于开发人员而言,仅基于构建配置来实现此目标很典型,并且我相信MSBuild(和dotnet)基于Web中的<DependentUpon>Web.config</DependentUpon>元素知道如何执行此操作.项目或构建脚本文件.

I think it's typical for developers to make this happen based on build configuration only, and I believe MSBuild (and dotnet) know how to do this based on the <DependentUpon>Web.config</DependentUpon> element in the Web.[configuration].config item in the project or build script file.

Azure DevOps 发布管道 有些不同. 管道要在构建/发布项目后转换您的web.config,并且如果MSBuild(或dotnet)已经尝试过,则不知道该怎么做.因此:

Azure DevOps Release Pipelines is a little different. The pipeline wants to transform your web.config after the project has been built/published and doesn't know how to do that if MSBuild (or dotnet) has already made an attempt at it. Thus:

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

[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 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.

警告文字指出:

  1. 删除csproj中每个配置的<DependentUpon>标记
    • 因此:您需要从csproj中删除标签,以防止MSBuild转换文件
    • 或者:您需要对MSBuild使用/p:TransformWebConfigEnabled=False参数.
      (注意:我相信可以在不删除依赖标签的情况下使用它,但这是正确的,但我可能是错的)
  1. Remove the <DependentUpon> tag for each config in the csproj
    • Thus: you need to remove the tag from the csproj to prevent MSBuild from transforming the files
    • Or: you need to use the /p:TransformWebConfigEnabled=False argument to MSBuild.
      (note: I believe it is correct that this can be used w/o removing the dependent upon tag, but I could be wrong)
  • 可能有几种方法可以做到这一点.我选择将转换源配置文件标记为内容,以强制MSBuild将它们包含在已发布的程序包中.

现在,您需要根据

Now you need to organize your release pipeline in accordance with the File Transforms and Value Substitutions documentation.

[节]开始:IIS Web App部署
====================================
任务:IIS Web App部署
描述:使用Web Deploy部署网站或Web应用程序
版本:0.0.51
作者:微软公司
帮助:
更多信息
==================================== ...
[命令] 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转换成功应用
...

[section]Starting: IIS Web App Deploy
====================================
Task : IIS Web App Deploy
Description : Deploy a website or web application using Web Deploy
Version : 0.0.51
Author : Microsoft Corporation
Help : More information
==================================== ...
[command]C:...\ctt\ctt.exe s:C:...\Web.config t:C:...\Web.Release.config d:C:...\Web.config pw i
[command]C:...\ctt\ctt.exe s:C:...\Web.config t:C:...\Web.Development.config d:C:...\Web.config pw i
XML Transformations applied successfully
...



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

将.config文件获取到发布管道可能有几种方法.这是两个.



For Non-Web Applications Needing .config Transformation

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

  1. 您的发行版应具有对工件的访问"权限,作为工件的一部分,这将确保部署代理下载源(不希望使用的IMHO).

  1. Your release should have "access" to the repository as a part of the artifact, which will ensure that the deploy agent downloads the source (not desirable IMHO).

您将需要将web.[stage] .config文件作为构建工件的一部分包含在复制任务中,或者将其与minimatch一起使用.

You will need to include the web.[stage].config files as part of your build artifact with a copy task, or a minimatch that picks them up.

一旦您有.config文件可用于发布管道

您可以使用 XDT转换任务来执行转换操作.

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

You can use the File Transform Task or XDT Transform Task to perform the transformation operations.

选项2是我走过的路线.

Option 2 is the route I've gone.

这是该任务对我的外观的图像.

Here is an image of what that task looks like for me.

该任务将配置放入构建版本中的构件中,然后可以在发布管道中使用该构建,而无需重新构建xx次.

That task puts the config in the artifact from the build that I can then use in the release pipeline without rebuilding xx times.

如果您希望不在发行完成后将转换文件保留在代理上,则需要将其添加到管道中.

If you're in a position where you care to not have the transform files persisting on the agent after the release is complete, then you'll need to add that to your pipeline.

这篇关于如何在Web部署zip中包含我的配置转换文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆