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

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

问题描述

我正在 Azure Devops 中设置新的构建和部署管道.它是一个较旧的 Web 应用程序,带有一些用于 web.config 的转换文件.在过去,我们会根据环境的数量构建相同的代码 x 次.这不再是必要的,因为我从这里阅读

<块引用>

[section]开始:IIS Web App 部署
====================================
任务:IIS Web App部署
描述:使用 Web Deploy 部署网站或 Web 应用程序
版本:0.0.51
作者:微软公司
帮助:

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

清理

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

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.

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?

解决方案

For Web applications

MSBuild knows how to transform the web.config files based on the following settings/properties/parameters (in order)

  • 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

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 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:

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

The warning text states:

  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)
  2. Make sure the transform source and target files are in the same folder inside the package.
    • There may be several ways to do this. I've chosen to mark the transform source config files as content to force MSBuild to include them in the published package.

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

[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:...cttctt.exe s:C:...Web.config t:C:...Web.Release.config d:C:...Web.config pw i
[command]C:...cttctt.exe s:C:...Web.config t:C:...Web.Development.config d:C:...Web.config pw i
XML Transformations applied successfully
...



For Non-Web Applications Needing .config Transformation

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

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

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

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.


Option 2 is the route I've gone.

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

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

Cleanup

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天全站免登陆