在Windows 2012服务器上使用Web部署,如果部署包含充满用户生成内容的文件夹,则将其从.pubxml文件中的发布中排除:
<ExcludeFoldersFromDeployment>somefoldername</ExcludeFoldersFromDeployment>
如果您使用“ 删除目标位置上的其他文件”选项进行部署,则此文件夹中的文件仍会从实时服务器中删除。
<SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>
有什么方法可以使部署过程(包括清理活动服务器)忽略指定的文件夹吗? 我想知道发布过程也会从服务器中删除已删除或已修改的文件,但是删除用户生成的数据的整个文件夹显然是一个问题!
以下是我的CustomProfile.pubxml文件,我用它来保留LetsEncrypt的.well-known文件夹以及其他文件夹。 以粗体添加以下项目以排除处理服务器上的文件,例如用户生成的内容。 这只在Visual Studio 2017和Server 2016上进行了testing。
<?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>
像这样的事情会做到这一点:
<?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>
我在这里有一个详细的post:
使用MsDeploy发布configuration文件.pubxml在IIS上创build一个空文件夹结构,并跳过使用MsDeploySkipRules删除它