I have an Azure DevOps Pipeline which includes an Azure App Service Deploy task (AzureRmWebAppDeployment
) for deploying an ASP.NET Core 3.1 project:
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Azure Subscription(01234567-89ab-cdef-0123-456789abcdef)'
appType: 'webApp'
WebAppName: 'MyStagingSite'
packageForLinux: '$(Build.ArtifactStagingDirectory)/**/*.zip'
enableCustomDeployment: true
DeploymentType: 'webDeploy'
enableXmlTransform: false
enableXmlVariableSubstitution: true
RemoveAdditionalFilesFlag: false
The Azure App Service destination, however, contains files in several pre-established folders which are managed independent of the continuous delivery process. We would like to use the Remove additional files at destination flag (RemoveAdditionalFilesFlag
) while leaving those folders intact.
Disclaimer: I don't consider this a best practice and, in the future, we will be moving these files off to a separate storage location. Until then, I'd like to find a solution that will work resolve this.
In Visual Studio 2019, we achieve this by excluding those files from our publishing process using the MsDeploySkipRules
in our csproj
file:
<Project Sdk="Microsoft.NET.Sdk.Web">
…
<ItemGroup>
<MsDeploySkipRules Include="CustomSkipFolder">
<ObjectName>dirPath</ObjectName>
<AbsolutePath>wwwroot\\Uploads</AbsolutePath>
</MsDeploySkipRules>
</ItemGroup>
</Project>
This approach works well for Visual Studio and is honored by its web deployment publishing process. These rules do not appear to be honored by the AzureRmWebAppDeployment
task, however, even when using the "Web Deploy" deployment method (DeploymentType
).
Is there a way to honor the MsDeploySkipRules
when using the AzureRmWebAppDeployment
task? If not, if there a way to provide a list of folders which should be skipped or ignored as part of the deployment process? Or, alternatively, if there another task that will permit one of these options when publishing to an Azure App Service?
Note: I also posted this to the DevOps Beta, but as the site hasn't reached critical mass yet, I'm cross-posting it here.
As @yang-shen-msft notes in the accepted answer, 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 Additional Arguments (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, the following provides additional details.
csproj
formatFirst, it's useful to recognize that when you deploy a project via Visual Studio, it's simply taking the MSDeploySkipRules
configured in the csproj
file and adding them to its internal call of msdeploy.exe
as -skip
rules. So, given the following rule defined in the csproj
:
<Project Sdk="Microsoft.NET.Sdk.Web">
…
<ItemGroup>
<MsDeploySkipRules Include="CustomSkipFolder">
<ObjectName>dirPath</ObjectName>
<AbsolutePath>wwwroot\\Uploads</AbsolutePath>
</MsDeploySkipRules>
</ItemGroup>
</Project>
The -skip
rule is interpreted as:
msdeploy.exe -skip:objectName=dirPath,absolutePath=wwwroot\\Uploads
Translating this to the Azure App Service Deploy (AzureRmWebAppDeployment
) task, the resulting yml
might look like:
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Azure Subscription'
appType: 'webApp'
WebAppName: 'MyStagingSite'
packageForLinux: '$(Build.ArtifactStagingDirectory)/**/*.zip'
enableCustomDeployment: true
DeploymentType: 'webDeploy'
enableXmlTransform: false
enableXmlVariableSubstitution: true
RemoveAdditionalFilesFlag: true
AdditionalArguments: '-skip:objectName=dirPath,absolutePath=wwwroot\\Uploads'
Note that multiple -skip
rules can be defined on the same msdeploy.exe
call.
AdditionalArguments: '-skip:objectName=dirPath,absolutePath=wwwroot\\Uploads -skip:objectName=dirPath,absolutePath=wwwroot\\Downloads'
-skip
Rules DocumentationUnfortunately, as mentioned above, there doesn't appear to be any official, first-party documentation for the -skip
rules on msdeploy.exe
. The 2014 documentation acknowledges them, and provides two examples, but doesn't expand on the options. That said, way back in 2012, @richard-szalay wrote a useful article, "Demystifying MSDeploy skip rules", which provides a lot of details for anyone requiring additional control.
The ObjectName
refers to the Web Deploy Provider, which can be used to update far more than just the file system.
I am setting ObjectName
to the dirPath
Web Deploy Provider so that I can skip entire directories. If you want to skip files, use filePath
instead.
Both dirPath
and filePath
accept regular expressions in the AbsolutePath
, potentially allowing repetitive rules following a consistent pattern to be consolidated.
The AbsolutePath
is actually relative to your publishing root—e.g., D:\home\site\wwwroot
on an Azure App Service.
As I am publishing an ASP.NET Core site, my static files are, by convention, in a nested wwwroot
folder, thus my setting:
absolutePath=wwwroot\\Uploads
actually maps to:
D:\home\site\wwwroot\wwwroot\Uploads
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With