问题
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