Search code examples
iismsdeploy

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?


Solution

  • 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>