如何阻止msbuild在Azure Devops管道中转换web.config [英] How to stop msbuild from transforming web.config in azure devops pipelines

查看:98
本文介绍了如何阻止msbuild在Azure Devops管道中转换web.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASP.NET MVC应用程序,我们已经开始将其转移到天蓝色的devops(代码和管道)中.我们有多个web.config文件,每个文件用于一个环境(测试,发布等).之前,我们已经构建了用于本地发布的系统,并将zip导入了IIS.在本地发行版(单击鼠标右键,发行版)期间,Visual Studio将获取与当前构建配置相关的Web.*.config文件(在本例中为Release),并将其与基本Web.config合并到单个Web.config文件中.

I'm working with an ASP.NET MVC application which we've started to move up into azure devops (code and pipelines). We have multiple web.config files, one for each environment (test, release, etc.) Earlier, we've built the system for release locally and imported the zip into IIS. During local release (right-click, release), Visual studio takes the Web.*.config file relevant to the current build configuration (Release in our case) and merges it with the base Web.config into a single Web.config file.

使用管道时,我们的目标是在构建步骤中转换Web.config文件,而在发布步骤中转换.我们要构建1个程序包,并在测试,暂存和生产服务器上使用同一程序包,而是使用

Our goal when using pipelines is to not transform the Web.config files in the build step, but instead in the release step. We want to build 1 package, and use that same package on our test, staging and production server, and instead use the xml transform setting in the release pipeline to deliver a different web.config file to different environments. We feel more confident in our process if the same binary is tested all the way through from test to release.

但是,无论我使用什么设置,只要我使用构建解决方案"步骤,它都会始终进行Web.config文件的转换.

However, whenever I use the "build solution" step it always does the Web.config file transform, no matter which settings I use.

到目前为止,我所做的是:我看过MS文档,但没有发现任何相关的内容.我搜索了SO,发现了一些线程,例如:解决方法并不能真正与我们的项目一起工作设置好了.我已经此github问题删除了<相关Web.*.config文件的code>< DependentUpon> 标记.不幸的是,没有任何帮助.

What I've done so far: I've looked at MS documentation but haven't found anything relevant. I've searched through SO and found some threads, this one for instance: web.config transformation does not work on build server says that you need a TransformXml emelent in your .csproj-file for XML transformations to work, but we don't have one, so I can't remove it and see if that helps :) Most threads seem to suggest passing different flags to msbuild to stop it from transforming the xml file (listed below) but none seem to work. I've found a workaround that doesn't really work with how our project is set up. I've per this github issue removed the <DependentUpon> tags for the relevant Web.*.config files. Unfortunately, nothing has helped.

这是构建步骤的YAML:

This is the YAML for the build step:

steps:
- task: VSBuild@1
  displayName: 'Build solution'
  inputs:
    solution: '**\Source\[redacted]Solution\*.sln'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\" /p:PreBuildEvent="" /p:TransformWebConfigEnabled=false /p:AutoParameterizationWebConfigConnectionStrings=false /p:MarkWebConfigAssistFilesAsExclude=false /p:ProfileTransformWebConfigEnabled=false'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

这些是自之前以来在项目中设置的构建标志:

These are the build flags set in the project since before:

/p:DeployOnBuild=true
/p:WebPublishMethod=Package
/p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:PackageLocation="$(build.artifactstagingdirectory)\\"
/p:PreBuildEvent=""

这些是我尝试用来在构建管道中禁用Web.Config转换的标志,似乎没有一个起作用(尝试了不同的组合):

These are the flags I've tried to use to try to disable Web.Config transformations in build pipeline, none seem to work (tried different combinations):

/p:TransformWebConfigEnabled=false
/p:AutoParameterizationWebConfigConnectionStrings=false
/p:MarkWebConfigAssistFilesAsExclude=false
/p:ProfileTransformWebConfigEnabled=false

那么,我需要传递给Azure Pipelines中的msbuild哪些标志,以使其转换Web.*.config文件?

So, which flags do I need to pass to msbuild in Azure Pipelines to make it not transform the Web.*.config file?

推荐答案

我需要传递给Azure Pipelines中的msbuild哪些标志,以使其不转换Web.*.config文件?

which flags do I need to pass to msbuild in Azure Pipelines to make it not transform the Web.*.config file?

您可以尝试使用MSBuild参数:

You can try to use the MSBuild argument:

/p:IsTransformWebConfigDisabled = true .

/p:IsTransformWebConfigDisabled=true.

作为测试,它在我这一边工作正常:

As test, it works fine on my side:

没有/p:IsTransformWebConfigDisabled = true ,我的测试 web.config 将被转换为:

Without /p:IsTransformWebConfigDisabled=true, my test web.config will be transformed to:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\WebAppTransform.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" hostingModel="InProcess"></aspNetCore>
  </system.webServer>
</configuration>

添加/p:IsTransformWebConfigDisabled = true ,则测试 web.config 不会被转换:

Add /p:IsTransformWebConfigDisabled=true, the test web.config is not be transformed:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
    </aspNetCore>
  </system.webServer>
</configuration>

希望这会有所帮助.

这篇关于如何阻止msbuild在Azure Devops管道中转换web.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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