How to exclude artifact files after web deployment?

Solution 1:

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

Solution 2:

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