0
votes

I have defined a release in AzureDevops to deploy my aspnet core app to on-premise IIS server. It copies all files successfully, but the can not transform the webconfig file correctly. However when I publish the app using VS webdeploy with same web.release.config, it transforms the web.config correctly.

I have checked the checkbox of "XML transformation" and "XML variable substitution" under "File Transforms & Variable Substitution Options".

The final web.config produced by azuredevops deployment, has duplicate xml elements for the ones that I used "xdt:Transform=Insert" and also it lacks the xml element for "environmentVariable".

Here is the transform file I have:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <modules xdt:Transform="Insert" runAllManagedModulesForAllRequests="false">
        <remove name="WebDAVModule" />
      </modules>
      <aspNetCore>
        <environmentVariables>
          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" xdt:Locator="Match(name)" xdt:Transform="SetAttributes" />
        </environmentVariables>
      </aspNetCore>
      <staticContent xdt:Transform="Insert">
        <mimeMap fileExtension="mp3" mimeType="..." />
      </staticContent>
    </system.webServer>
  </location>
</configuration>

And here is the result web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <location path="." inheritInChildApplications="false">
        <system.webServer>
            <handlers>
                <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
            </handlers>
            <aspNetCore processPath="dotnet" arguments=".\app.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
            <modules runAllManagedModulesForAllRequests="false">
                <remove name="WebDAVModule" />
            </modules>
            <staticContent>
                <mimeMap fileExtension="mp3" mimeType="..." />
            </staticContent>
            <modules runAllManagedModulesForAllRequests="false">
                <remove name="WebDAVModule" />
            </modules>
            <staticContent>
                <mimeMap fileExtension="mp3" mimeType="" />
            </staticContent>
        </system.webServer>
    </location>
</configuration>

My azure-pipelines.yml is as follow :

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

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:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

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

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'
2

2 Answers

1
votes

I tested with your yaml pipeline. When i checked the build log of Vsbuild task, i found the web.config was automatically created and applied the transformation. When i downloaded the build artifacts and checked the web.config file, the file was correctly transformed. No duplication elements and No missing element.

enter image description here

The duplicate xml elements you encountered is because if the XML transformation is enabled in release pipeline, the web.config that has been transformed by Vsbuild task will be transformed again, which caused the duplication. ()

The possible fix is to disable the XML transformation of your release pipeline, since the transformation was done by vsbuild task.

Or you can add a flag /p:IsTransformWebConfigDisabled=true to msbuild arguments to prevent Vsbuild task from transforming web.config file in build pipeline. Then you can enable XML transformation in the release pipeline.

0
votes

Make sure the web.PROFILENAME.config file is set to Content

https://stackoverflow.com/a/35466754/16940