9

Using Web Deploy on a Windows 2012 Server, if a deployment has a folder full of user generated content I exclude it from publishing in the .pubxml file with:

<ExcludeFoldersFromDeployment>somefoldername</ExcludeFoldersFromDeployment>

If you use the Remove additional files at destination option for deploying, files in this folder are still removed from the live server.

<SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>

Is there any way to make the deployment process, including the clean-up of the live server, ignore a specified folder? I like knowing the publish process also removes deleted or modified files from the server, but wiping out entire folders of user generated data is obviously a problem!

Polynomial
  • 191
  • 1
  • 4

2 Answers2

2

The following is my CustomProfile.pubxml file that I use to leave my .well-known folder for LetsEncrypt, as well as other folders alone. Add the items below in bold to exclude processing files on the server, such as user generated content. This has only been tested on Visual Studio 2017, with 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>
Vince Pike
  • 125
  • 6
  • Were you able to open/run your modified publish file from within Visual Studio? For me (VS2017) once I modify it, it then fails to recognise it. – Dale K Oct 02 '19 at 22:36
  • Dale, I did indeed modify it from Visual Studio. Perhaps you have something else going on. Do you have an error message or anything? – Vince Pike Oct 04 '19 at 19:48
  • @DaleK Visual Studio caches it, so you need to restart VS after changing the file. – spaark Aug 18 '20 at 09:56
1

Something like this will do it:

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

I have a detailed post here:

Using MsDeploy publish profile .pubxml to create an empty folder structure on IIS and skip deleting it with MsDeploySkipRules

  • Were you able to open/run your modified publish file from within Visual Studio? For me (VS2017) once I modify it, it then fails to recognise it. – Dale K Oct 02 '19 at 22:37