3

Using Microsoft's documentation plus this answer I am trying to get my Web.Config transform files to be deployed as Azure DevOps artifacts so that I can apply different transforms while publishing builds into different environments.

My goal is to:

  1. Set debug=false for all environments (or remove the attribute entirely, which is seemingly only possible by a transform file)
  2. Change an <appsettings/> value for each deployment environment.

As per the above links, I set my Web.Release.Config file to copy to the output directory:

enter image description here

This is verified in the project file:

<Content Include="Web.Release.config">
  <DependentUpon>Web.config</DependentUpon>
  <SubType>Designer</SubType>
  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

When this change is merged to the Master branch (triggering a build and release) I see in the artifacts ZIP file that only the original web.config file from development is there. No transform files are published to DevOps.

enter image description here

Reading into this further I am aware that transformations have to be prevented in the YAML file so that the <DependentUpon>Web.Config setting can be maintained for a cleaner solution explorer, so have done this also:

- task: VSBuild@1
  inputs:
    solution: '$(Build.SourcesDirectory)\My App\App Project 03.csproj'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PrecompileBeforePublish=true;EnableUpdateable=false /p:TransformWebConfigEnabled=False /p:AutoParameterizationWebConfigConnectionStrings=False /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

What am I missing please, or am I going about this all wrong??

EvilDr
  • 8,943
  • 14
  • 73
  • 133

1 Answers1

1

Generally you need the transform config files to be included in the yaml pipeline to determine what kind of environment it's running on (development, debug etc), but there's a certain flag that needs to be set for this to happen, namely TransformWebConfigEnabled in this case it doesn't appear to be properly set which could be a reason for why they aren't being included in the zip file.

Set the flag to true in the msbuildargs and the issue should be solved

An example of the new msbuildargs that would accomplish this could be:


... Other parts...

msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PrecompileBeforePublish=true;EnableUpdateable=false /p:TransformWebConfigEnabled=True /p:AutoParameterizationWebConfigConnectionStrings=False /p:TransformFile="Web.Release.config" /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'


... Continuation
  • Could be please clarify a little as `TransformWebConfigEnabled=True` contradicts with [this](https://www.herlitz.io/2020/01/10/web.config-transforms-not-working-in-azure-devops-pipeline/) and [this](https://medium.com/@dvinun/got-web-config-transformation-problem-in-your-azure-devops-953a8f29335b) tutorial to ensure that further transformations using DevOps variables are possible in the release pipelines? – EvilDr Feb 10 '23 at 10:39
  • Alternatively is there any resource where all these parameters/values are documented? I thought MS Learn would have them against the MSBuild/VSBuild pages but `TransformWebConfigEnabled` is not included – EvilDr Feb 10 '23 at 11:42