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

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

在 Windows 2012 Server 上使用 Web Deploy,如果部署中有一个文件夹充满用户生成的内容,我会使用以下命令将其排除在文件中发布之外.pubxml

<ExcludeFoldersFromDeployment>somefoldername</ExcludeFoldersFromDeployment>

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

<SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>

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

答案1

以下是我的 CustomProfile.pubxml 文件,我使用它来保留 LetsEncrypt 的 .well-known 文件夹以及其他文件夹。添加以下粗体项目以排除服务器上的处理文件,例如用户生成的内容。这仅在 Visual Studio 2017 和 Server 2016 上进行了测试。

<?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 
https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developermsbuild/2003">

<PropertyGroup>
  <WebPublishMethod>MSDeploy</WebPublishMethod>
</PropertyGroup>

<PropertyGroup>
  <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
  <LastUsedPlatform>Any CPU</LastUsedPlatform>
  <SiteUrlToLaunchAfterPublish>https://www.vinceworks.com</SiteUrlToLaunchAfterPublish>
  <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
  <ExcludeApp_Data>True</ExcludeApp_Data>
  <MSDeployServiceURL>https://www.vinceworks.com</MSDeployServiceURL>
  <DeployIisAppPath>VinceWorks</DeployIisAppPath>
  <RemoteSitePhysicalPath />
  <SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>
  <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
  <EnableMSDeployBackup>True</EnableMSDeployBackup>
  <UserName>Vince</UserName>
  <_SavePWD>True</_SavePWD>
  <PrecompileBeforePublish>True</PrecompileBeforePublish>
  <EnableUpdateable>True</EnableUpdateable>
  <DebugSymbols>False</DebugSymbols>
  <WDPMergeOption>DonotMerge</WDPMergeOption>
</PropertyGroup>

<ItemGroup>
  <MsDeploySkipRules Include="CustomSkipFolder">
    <ObjectName>dirPath</ObjectName>
    <AbsolutePath>VinceWorks\\\.well-known</AbsolutePath><!--Regular Expression here-->
  </MsDeploySkipRules>
</ItemGroup>

<ItemGroup>
  <MsDeploySkipRules Include="CustomSkipFolder">
    <ObjectName>dirPath</ObjectName>
    <AbsolutePath>VinceWorks\\Media</AbsolutePath>
  </MsDeploySkipRules>
</ItemGroup>

<ItemGroup>
  <MsDeploySkipRules Include="CustomSkipFolder">
    <ObjectName>dirPath</ObjectName>
    <AbsolutePath>\\Views</AbsolutePath>
  </MsDeploySkipRules>
</ItemGroup>

</Project>

答案2

类似这样的事情就可以做到:

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

我在这里有一个详细的帖子:

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

相关内容