Reputation: 368
I have an ASP.Net framework (v4.7) web application which I have a build pipeline for in Azure Devops Server (2019).
There is a Visual Studio Build task which builds the solution fine and publishes out the site to the _PublishedWebsites
folder. The trouble is, the web.config transform for the release has not been applied and it still has debug="true"
set which is not what I want for automated deployment.
The msbuild arguments for the task are: /p:outdir="$(build.artifactstagingdirectory)"
and the BuildConfiguration variable for the build is set to release
.
When I have published the project using visual studio the web.release.config transform is applied and the debug attribute has been removed from the web.config file in the published content.
Is there something I am missing here?
Edit: Build pipeline YAML:
queue:
name: Default
demands:
- msbuild
- visualstudio
#Your build pipeline references an undefined variable named ‘Parameters.solution’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘Parameters.solution’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references the ‘BuildPlatform’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildPlatform’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references an undefined variable named ‘Parameters.ArtifactName’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
steps:
- task: NuGetCommand@2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(Parameters.solution)'
- task: VSBuild@1
displayName: 'Build solution'
inputs:
solution: '$(Parameters.solution)'
vsVersion: 16.0
msbuildArgs: '/p:outdir="$(build.artifactstagingdirectory)"'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
- task: VisualStudioTestPlatformInstaller@1
displayName: 'Visual Studio Test Platform Installer'
inputs:
versionSelector: latestStable
- task: VSTest@2
displayName: 'Test Assemblies'
inputs:
testAssemblyVer2: |
$(build.artifactstagingdirectory)\*test*.dll
!**\obj\**
vsTestVersion: toolsInstaller
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
- task: PublishSymbols@2
displayName: 'Publish symbols path'
inputs:
SearchPattern: '**\bin\**\*.pdb'
PublishSymbols: false
continueOnError: true
- script: |
cd ProjectName.Web.CMS
copy cmsimport.lic bin /y
displayName: 'Copy CMSImport licence to bin folder'
- script: |
ECHO Copying over the umbraco, umbraco_client and CMSImport content for deployment.
xcopy ProjectName.Web.CMS\packages\UmbracoCms.7.5.14\UmbracoFiles\umbraco $(build.artifactstagingdirectory)\_PublishedWebsites\ProjectName.Web.CMS\umbraco\ /s /e /r /y
xcopy "ProjectName.Web.CMS\packages\UmbracoCms.7.5.14\UmbracoFiles\umbraco_client" $(build.artifactstagingdirectory)\_PublishedWebsites\ProjectName.Web.CMS\umbraco_client\ /s /e /r /y
xcopy ProjectName.Web.CMS\packages\CMSImport.3.5\content\umbraco $(build.artifactstagingdirectory)\_PublishedWebsites\ProjectName.Web.CMS\umbraco\ /s /e /r /y
displayName: 'Copy umbraco related content to staging'
enabled: false
- script: |
cd ProjectName.Web.CMS
move robots_UAT.txt $(build.artifactstagingdirectory)\_PublishedWebsites\ProjectName.Web.CMS\robots.txt
displayName: 'Add robots.txt file to artifacts staging directory'
- task: ArchiveFiles@2
displayName: 'Archive $(build.artifactstagingdirectory)\_PublishedWebsites\ProjectName.Web.CMS\'
inputs:
rootFolderOrFile: ' $(build.artifactstagingdirectory)\_PublishedWebsites\ProjectName.Web.CMS\'
includeRootFolder: false
archiveFile: '$(Build.ArtifactStagingDirectory)/ProjectName.Web.CMS.zip'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)\ProjectName.Web.CMS.zip'
ArtifactName: '$(Parameters.ArtifactName)'
Upvotes: 5
Views: 3118
Reputation: 57
msbuild will perform the transform only if below task in written in your project (csproj) file
<Target Name="AfterBuild"> </Target>
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="Web_config_AfterBuild" AfterTargets="AfterBuild" Condition="Exists('Web.$(Configuration).config')">
<TransformXml Source="Web.config" Destination="$(OutputPath)Web.config" Transform="Web.$(Configuration).config" />
</Target>
Upvotes: 0
Reputation: 368
I managed to get the transform to apply after adding in the XDT Transform build task to my Azure DevOps build server.
I did some reading which indicated that the transforms as part of a CI/CD pipeline are applied as part of the Azure App Service deploy or IIS deploy release tasks and not carried out by msbuild.
This is also an interesting article. Unfortunately the File Transform build task is pre-release and you have to build the task from source yourself if you are using Azure DevOps Server on-prem. I had a go but after installation of the package the task was not showing as being available to add. The XDT Transform task was a good replacement and does the job nicely.
Upvotes: 4