'How to exclude artifact files after web deployment?

We have a build/release pipeline that is finally working correctly, but the developer asked that we exclude the stage config files (Web.Dev.config, Web.Test.config, Web.Prod.config) as well as the artifact archive itself from the site/wwwroot.

As you can see, every time we deployed, these zip files have been getting stored in the site root as well. They aren't harmful but it doesn't look good:

wwwroot

This is the Release App Service Web Deploy YAML:

steps:
- task: AzureRmWebAppDeployment@4
  displayName: 'Azure App Service Deploy: project-123'
  inputs:
    azureSubscription: 'Azure Dev Service Connection'
    WebAppName: 'project-123'
    packageForLinux: '$(System.DefaultWorkingDirectory)/Project123 Dev Build Artifact/Release'
    enableCustomDeployment: true
    enableXmlTransform: true

How do we exclude those files after successful deployment?

Kudu dir structure:

kudu dir



Solution 1:[1]

Building on @theWinterCoder answer, Unfortunately, there doesn’t appear to be a way to honor the MSDeploySkipRules defined in the csproj file. Instead, files and folders can be skipped by defining the AdditionalArguments parameter of the Azure App Service Deploy (AzureRmWebAppDeployment) task.

Since there doesn’t appear to be any official documentation for the -skip rules, and the MSDeploy.exe documentation that Azure Pipelines references is out-of-date, in 2012, richard-szalay wrote a useful article, “Demystifying MSDeploy skip rules”, which provides a lot of details for anyone requiring additional control.

Brief Explanation:

The dirPath argument represents the Web Deploy Provider to skip a directory whilst the filePath argument is used to skip an individual file. The dirPath starts at wwwroot. For ASP.NET Core applications, there’s another wwwroot under wwwroot; as such, the absolutePath in that case would look like this: absolutePath=wwwroot\\somefoldername which would map to D:\home\site\wwwroot\wwwroot\somefoldername

Solution:

Therefore, since I’m skipping files, i set the web deploy provider to filePath, and since we’re not using .NET Core, we set absolutePath to Web.Dev.config. That would map to D:\home\site\wwwroot\Web.Dev.config. The same thing applies for the zip artifact, however, if we don’t prepend \\ before the wildcard it will fail with following error:

Error: Error: The regular expression '.zip’ is invalid. Error: parsing ".zip" - Quantifier {x,y} following nothing. Error count: 1.

-skip:objectName=filePath,absolutePath=Web.Dev.config 
-skip:objectName=filePath,absolutePath=Web.Prod.config 
-skip:objectName=filePath,absolutePath=Web.Test.config 
-skip:objectName=filePath,absolutePath=\\*.zip

or with regular expression:

-skip:objectName=filePath,absolutePath="Web.Dev.config|Web.Prod.config|Web.Test.config|\\*.zip"

Thats it ?

Dir

Solution 2:[2]

You can add an additional arguments line to the yml that will tell it to skip certain files. It will look something like this:

AdditionalArguments: '-skip:objectName=dirPath,absolutePath=wwwroot\\Uploads'

More details can be found in this thread

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 TheWinterCoder