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'