user626528
user626528

Reputation: 14419

How do I preserve existing files when installing an MSDeploy package?

I need to preserve some files, generated by my site.

Is it possible to make MSDeploy not delete any files, and overwrite existing files only when the package contains a newer version of a file?

Upvotes: 3

Views: 2331

Answers (2)

user626528
user626528

Reputation: 14419

The solution was to add this code into my csproj file, it prevents any deletions and updates in App_Data folder on deploy:

  <PropertyGroup>
    <OnBeforePackageUsingManifest>AddSkipRules</OnBeforePackageUsingManifest>
  </PropertyGroup>
  <Target Name="AddSkipRules">
    <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>
      <MsDeploySkipRules Include="SkipUpdateAppData">
        <SkipAction>Update</SkipAction>
        <ObjectName>filePath</ObjectName>
        <AbsolutePath>$(_Escaped_PackageTempDir)\\App_Data\\.*</AbsolutePath>
        <XPath>
        </XPath>
      </MsDeploySkipRules>
      <MsDeploySkipRules Include="SkipUpdateAppData">
        <SkipAction>Update</SkipAction>
        <ObjectName>dirPath</ObjectName>
        <AbsolutePath>$(_Escaped_PackageTempDir)\\App_Data\\.*</AbsolutePath>
        <XPath>
        </XPath>
      </MsDeploySkipRules>
    </ItemGroup>
  </Target>

Upvotes: 1

Charles Lambert
Charles Lambert

Reputation: 5132

-enableRule:SkipNewerFilesRule will skip updates to files that have a more recent write time. -enableRule:DoNotDeleteRule will block deletion of files on the destination computer, but this rule only works with the contentPath, dirPath, and filePath providers. I have used the skipRule -skip:skipAction=Delete,objectName=dirPath,absolutePath=.* to simulate the DoNotDeleteRule. It has worked well for me so far.

Upvotes: 2

Related Questions