1

I have a build pipeline which publishes a build artifact to path $(Build.ArtifactStagingDirectory). I have a release pipeline with 1 stage following the IIS website deployment template. The IIS web App Deploy task is set to use Xml Transformation, and the deployment executes successfully. The website is created in IIS, but the web.config is not transformed correct.

My Stage is called "MyEnvironment", and I have a web.config and a web.MyEnvironment.Config file in the project, which transforms correctly in visual studio transform preview and if I publish from visual studio. If I look at the logs for my release pipeline, I see that the IIS Web App Deploy task executed successfully but there were warnings:

2022-02-09T19:05:07.5762631Z ##[warning]Unable to apply transformation for the given package. Verify the following.
2022-02-09T19:05:07.5773252Z ##[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. 
2022-02-09T19:05:07.5775568Z ##[warning]2. Ensure that the config file and transformation files are present in the same folder inside the package.

My understanding was that the xml transformation of an IIS Web App Deploy task would use the name of the stage as the environment when searching for the web.config transform to use. I'm sure that the stage name matches the web..config file, yet it is still not transforming correctly. Is there something I'm missing here?

trigger:
- Development

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
#    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)" /p:AutoParameterizationWebConfigConnectionStrings=False'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'
Jeremy
  • 44,950
  • 68
  • 206
  • 332

1 Answers1

0

You will need to turn off the transforms during the build in the yml and in the project file.

  1. In your yml file under the VSBuild@1 task in you msbuildArgs add /p:TransformWebConfigEnabled=false

  2. In your project file find

    <Content Include="web.MyEnvironment.config">
        <DependentUpon>web.config</DependentUpon>
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    

    And remove the <DependentUpon>web.config</DependentUpon> but make sure <CopyToOutputDirectory>Always</CopyToOutputDirectory> is there, you may need to add it.

When you build, your web.config and web.MyEnvironment.config should both be in the drop artifacts at the base level of your web app as well as in the bin folder, not just in the bin folder. The rest of your settings should be correct. You can reference this question as well.

Andrew
  • 1