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

巧了我就是萌 提交于 2020-01-23 11:45:11

问题


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?


回答1:


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




回答2:


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>


来源:https://stackoverflow.com/questions/8655915/how-do-i-preserve-existing-files-when-installing-an-msdeploy-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!