从部署中排除文件夹并停止其他文件删除

Pol*_*ial 9 iis deployment windows-server-2012

在 Windows 2012 服务器上使用 Web 部署,如果部署有一个充满用户生成内容的文件夹,我将其排除在.pubxml文件中发布:

<ExcludeFoldersFromDeployment>somefoldername</ExcludeFoldersFromDeployment>
Run Code Online (Sandbox Code Playgroud)

如果您使用在目标位置删除其他文件选项进行部署,此文件夹中的文件仍会从实时服务器中删除。

<SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>
Run Code Online (Sandbox Code Playgroud)

有什么办法可以让部署过程,包括清理live server的时候,忽略指定的文件夹?我喜欢知道发布过程也会从服务器中删除已删除或修改的文件,但清除用户生成数据的整个文件夹显然是一个问题!

Len*_*rri 1

像这样的事情会做到这一点:

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <AfterAddIisSettingAndFileContentsToSourceManifest>AddCustomSkipRules</AfterAddIisSettingAndFileContentsToSourceManifest>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <LastUsedBuildConfiguration>Local</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <MSDeployServiceURL>localhost</MSDeployServiceURL>
    <DeployIisAppPath>AppPath</DeployIisAppPath>
    <RemoteSitePhysicalPath />
    <SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>
    <MSDeployPublishMethod>InProc</MSDeployPublishMethod>
    <EnableMSDeployBackup>False</EnableMSDeployBackup>
    <UserName />
    <_SavePWD>False</_SavePWD>
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
  </PropertyGroup>

  <PropertyGroup>
    <UseMsDeployExe>true</UseMsDeployExe>
  </PropertyGroup>

  <Target Name="AddCustomSkipRules">
    <Message Text="Adding Custom Skip Rules" />
    <ItemGroup>
      <MsDeploySkipRules Include="SkipFilesFolder">
        <SkipAction>Delete</SkipAction>
        <ObjectName>filePath</ObjectName>
        <AbsolutePath>YourFolderNameHere</AbsolutePath>
      </MsDeploySkipRules>
    </ItemGroup>
  </Target>

</Project>
Run Code Online (Sandbox Code Playgroud)

我这里有一篇详细的帖子:

使用 MsDeploy 发布配置文件 .pubxml 在 IIS 上创建空文件夹结构,并使用 MsDeploySkipRules 跳过删除它