Zaixu
Zaixu

Reputation: 331

How to skip delete on folder during publish?

I cannot make it, so that the Publish from visual studio doesnt delete the App_Data folder on the server website. But i would also like it to keep deleting all files (except that folder) to keep the dir "clean".

I have tried this in csproj, .pubxml. And alterations of it (theres one not OnBeforePackageUsingManifest, but iis something)

<PropertyGroup>
  <OnBeforePackageUsingManifest>AddCustomSkipRules</OnBeforePackageUsingManifest>
</PropertyGroup>
<Target Name="AddCustomSkipRules">
  <ItemGroup>
    <MsDeploySkipRules Include="SkipDeleteAppData">
      <SkipAction>Delete</SkipAction>
      <ObjectName>filePath</ObjectName>
      <AbsolutePath>$(_Escaped_PackageTempDir)\\App_Data\\.*</AbsolutePath>
      <XPath>
      </XPath>
    </MsDeploySkipRules>
    <MsDeploySkipRules Include="SkipDeleteAppData">
      <SkipAction>Delete</SkipAction>
      <ObjectName>dirPath</ObjectName>
      <AbsolutePath>$(_Escaped_PackageTempDir)\\App_Data\\.*</AbsolutePath>
      <XPath>
      </XPath>
    </MsDeploySkipRules>
  </ItemGroup>
</Target>

I even get if i use "SkipAction=Delete" thats it is unable to do so, as Delete is not recognized.

Are there any way to do this? preferably from .pubxml, but csproj will do aswell. Not that much for having to deal with msdeploy command line.

Using visual studio 2015.

Upvotes: 6

Views: 5547

Answers (3)

Fernando Flores
Fernando Flores

Reputation: 53

If "Remove additional files at destination" and "Exclude files from the App_Data folder" are both selected, EVERYTHING will be still deleted first and App_Data folder will be ignored (It wont be published).

The only recommendation I can give is to make the folder hidden, this way even "Remove..." is checked it wont be deleted.

Upvotes: 0

Max
Max

Reputation: 3328

Came here looking for a way to keep the "certify the web" .wellknown\acme-challenge folders web.config during a Visual Studio 2019 publish. Thought I'd share it.

Adding the following to pubxml file will cause deploy NOT to delete the web.config during publish.

<ItemGroup>
  <MsDeploySkipRules Include="CustomSkipFile">
    <ObjectName>filePath</ObjectName>
    <AbsolutePath>.well-known\\acme-challenge\\web.config</AbsolutePath>
  </MsDeploySkipRules>
</ItemGroup>

Hope this helps somebody!

Upvotes: 3

superjos
superjos

Reputation: 12695

This (quite recent) SO answer mentions that MsDeploySkipRules settings are effective only when publishing through command line.

When Web Deploy-ing from VS IDE, it suggests checking the following options:

  • Remove additional files at destination
  • Exclude files from the App_Data folder

Web Publishing Profile

Upvotes: 0

Related Questions