<p>As @yang-shen-msft <a href="https://stackoverflow.com/a/60541274/3025856">notes on Stack Overflow</a>, there doesn't appear to be a way to honor the <code>MSDeploySkipRules</code> defined in the <code>csproj</code> file. Instead, files and folders can be skipped by defining the <em>Additional Arguments</em> (<code>AdditionalArguments</code>) parameter of the <em>Azure App Service Deploy</em> (<code>AzureRmWebAppDeployment</code>) task, <a href="https://stackoverflow.com/a/46961055/3025856">as discussed in another Stack Overflow answer</a>.</p>
<p>Since there doesn't appear to be any official documentation for the <code>-skip</code> rules, and <a href="https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/dd569089(v=ws.10)?redirectedfrom=MSDN" rel="nofollow noreferrer">the <code>MSDeploy.exe</code> documentation that Azure Pipelines references</a> is out-of-date, the following provides additional details.</p>
<p>First, it's useful to recognize that when you deploy a project via Visual Studio, it's simply taking the <code>MSDeploySkipRules</code> configured in the <code>csproj</code> file and adding them to it's internal call of <code>msdeploy.exe</code> as <code>-skip</code> rules. So, given the following rule defined in the <code>csproj</code>:</p>
<pre class="lang-xml prettyprint-override"><code>&lt;Project Sdk=&quot;Microsoft.NET.Sdk.Web&quot;&gt;
  …
  &lt;ItemGroup&gt;
    &lt;MsDeploySkipRules Include=&quot;CustomSkipFolder&quot;&gt;
      &lt;ObjectName&gt;dirPath&lt;/ObjectName&gt;
      &lt;AbsolutePath&gt;wwwroot\\Uploads&lt;/AbsolutePath&gt;
    &lt;/MsDeploySkipRules&gt;
  &lt;/ItemGroup&gt;
&lt;/Project&gt;
</code></pre>
<p>The <code>-skip</code> rule is interpreted as:</p>
<pre><code>msdeploy.exe -skip:objectName=dirPath,absolutePath=wwwroot\\Uploads
</code></pre>
<p>Translating this to the <em>Azure App Service Deploy</em> (<code>AzureRmWebAppDeployment</code>) task, the resulting <code>yml</code> might look like:</p>
<pre><code>- 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'
</code></pre>
<blockquote>
<p><em>Note:</em> Multiple <code>-skip</code> rules can be defined on the same <code>msdeploy.exe</code> call.</p>
</blockquote>
<p>Unfortunately, as mentioned above, there doesn't <em>appear</em> to be any official, first-party documentation for the <code>-skip</code> rules on <code>msdeploy.exe</code>. The <a href="https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/dd569089(v=ws.10)?redirectedfrom=MSDN" rel="nofollow noreferrer">2014 documentation</a> 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, &quot;<a href="https://blog.richardszalay.com/2012/12/17/demystifying-msdeploy-skip-rules/" rel="nofollow noreferrer">Demystifying MSDeploy skip rules</a>&quot;, which provides useful direction here for anyone requiring additional control over their <code>-skip</code> rules.</p>

CC BY-SA 4.0
2020-03-20T20:26:57.950Z
2020-08-18T19:10:12.463Z
2020-08-18T19:10:12.463Z
Jeremy Caney
<p>I have an <strong>Azure DevOps Pipeline</strong> which includes an <strong>Azure App Service Deploy</strong> task (<code>AzureRmWebAppDeployment</code>) for deploying an <strong>ASP.NET Core 3.1</strong> project:</p>

<pre><code>- 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
</code></pre>

<p>The <strong>Azure App Service</strong> destination, however, contains files in several pre-established folders which are managed independent of the continuous delivery process. We would like to use the <em>Remove additional files at destination</em> flag (<code>RemoveAdditionalFilesFlag</code>) while leaving those folders intact.</p>

<blockquote>
  <p><em>Disclaimer:</em> 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.</p>
</blockquote>

<p>In <strong>Visual Studio 2019</strong>, we achieve this by excluding those files from our publishing process using the <code>MsDeploySkipRules</code> in our <code>csproj</code> file:</p>

<pre class="lang-xml prettyprint-override"><code>&lt;Project Sdk="Microsoft.NET.Sdk.Web"&gt;
  …
  &lt;ItemGroup&gt;
    &lt;MsDeploySkipRules Include="CustomSkipFolder"&gt;
      &lt;ObjectName&gt;dirPath&lt;/ObjectName&gt;
      &lt;AbsolutePath&gt;wwwroot\\Uploads&lt;/AbsolutePath&gt;
    &lt;/MsDeploySkipRules&gt;
&lt;/Project&gt;
</code></pre>

<p>This approach works well for Visual Studio. Those rules do not appear to be honored by the <code>AzureRmWebAppDeployment</code> task, however, even when using the "Web Deploy" deployment method (<code>DeploymentType</code>).</p>

<p>Is there a way to honor the <code>MsDeploySkipRules</code> when using the <code>AzureRmWebAppDeployment</code> 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?</p>

<azure-devops><azure><azure-pipelines>
Azure Pipelines: Exclude folders using Azure App Service Deploy
Jeremy Caney
# Azure Pipelines: Exclude folders using Azure App Service Deploy

(Asked by: username_0 on 2020-02-28)

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:

  …
  
    
      dirPath
      wwwroot\\Uploads
    


This approach works well for Visual Studio. Those 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?

**Tags:** azure-devops, azure, azure-pipelines


---

## 1 answers

### Answer by username_0 on 2020-03-20. Score: 3 | Accepted answer

As @yang-shen-msft notes on Stack Overflow, 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, as discussed in another Stack Overflow answer.
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.
First, 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 it's internal call of msdeploy.exe as -skip rules. So, given the following rule defined in the csproj:

  …
  
    
      dirPath
      wwwroot\\Uploads
    
  


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: Multiple -skip rules can be defined on the same msdeploy.exe call.

Unfortunately, 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 useful direction here for anyone requiring additional control over their -skip rules.


---

