1

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.

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.

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

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.

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=""

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

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

Tobbe
  • 1,825
  • 3
  • 21
  • 37

1 Answers1

6

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

You can try to use the MSBuild argument:

/p:IsTransformWebConfigDisabled=true (ASP.NET Core)

(For older ASP.NET applications built with .NET Framework, use /p:TransformWebConfigEnabled=false)

As test, it works fine on my side:

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>

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>

Hope this helps.

Rudey
  • 4,717
  • 4
  • 42
  • 84
Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • @Tobbe, Anytime, let me know if it works for you for free. – Leo Liu Sep 18 '19 at 01:56
  • Hi, sorry for not responding! I've been sick and off work for a few days :) Yes, it seems to work great! I'm curious, how did you find that flag? I've looked hard but not fund a good reference for the msbuild flags. – Tobbe Sep 20 '19 at 08:58
  • @Tobbe, I'm sorry to hear that. Take care of your body! I used to be MSBuild technical support, I have the impression that I see this parameter in a blog and then test it. – Leo Liu Sep 20 '19 at 09:05
  • 1
    @Tobbe, Found it! http://www.peterdol.nl/posts/disable-web-config-transform-dotnet-core/ – Leo Liu Sep 20 '19 at 09:06
  • @Tobbe which flags do I need to pass to MSBuild in Azure Pipelines to make it transform the Web.*.config file? – Dharti Sutariya May 01 '20 at 07:27
  • @DhartiSutariya what you're asking is the opposite if what I did - I think that by passing *no* flag MSBuild will transform the Web.*.config file for you, where * is the name of your selected build config. – Tobbe May 01 '20 at 16:00
  • 1
    @DhartiSutariya, Probably I guess that you are trying to get the web..config to transform and it isn't happening? There is an issue with Multistage YAML pipeline that can be fixed by setting up an environment variable. Check Issue 3 specified in following page for detailed information - [XML transform issue in Azure DevOps](https://davidsekar.com/asp-net/stop-xml-transform-during-msbuild-step-in-azure-devops) – David Chelliah Nov 09 '21 at 19:39