Skip to content

Instantly share code, notes, and snippets.

@matijagrcic
Last active December 31, 2015 17:49
Show Gist options
  • Save matijagrcic/8023201 to your computer and use it in GitHub Desktop.
Save matijagrcic/8023201 to your computer and use it in GitHub Desktop.
<PropertyGroup>
<UseMsDeployExe>true</UseMsDeployExe>
</PropertyGroup>
<PropertyGroup>
<AfterAddIisSettingAndFileContentsToSourceManifest>AddCustomSkipRules</AfterAddIisSettingAndFileContentsToSourceManifest>
</PropertyGroup>
<Target Name="AddCustomSkipRules">
<ItemGroup>
<MsDeploySkipRules Include="SkipDownloadsFiles">
<SkipAction>Delete</SkipAction>
<ObjectName>filePath</ObjectName>
<AbsolutePath>.*\\Content\\UserPictures\\.*$</AbsolutePath>
<XPath></XPath>
</MsDeploySkipRules>
<MsDeploySkipRules Include="SkipDownloadsFolder">
<SkipAction>Delete</SkipAction>
<ObjectName>dirPath</ObjectName>
<AbsolutePath>.*\\Content\\UserPictures\\.*$</AbsolutePath>
<XPath></XPath>
</MsDeploySkipRules>
</ItemGroup>
</Target>
Working:
I want to include Remove Additional Files at destination but i don't want to delete the folders
and content from Content\UserPictures\ directory.
It needs to work from VS Publish not command line.
Not working:
In Web Publish dialog Preview is not showing any changes.
@sayedihashimi
Copy link

I just tried the following and it looked to work. Can you try 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>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish>http://mysite</SiteUrlToLaunchAfterPublish>
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <MSDeployServiceURL>myurl</MSDeployServiceURL>
    <DeployIisAppPath>sayedskip</DeployIisAppPath>
    <RemoteSitePhysicalPath />
    <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
    <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
    <EnableMSDeployBackup>True</EnableMSDeployBackup>
    <UserName>$sayedskip</UserName>
    <_SavePWD>True</_SavePWD>
    <PublishDatabaseSettings>
      <Objects xmlns="">
        <ObjectGroup Name="DefaultConnection" Order="1" Enabled="False">
          <Destination Path="" />
          <Object Type="DbCodeFirst">
            <Source Path="DBContext" DbContext="SkipCustomFolders.Models.ApplicationDbContext, SkipCustomFolders" Origin="Configuration" />
          </Object>
        </ObjectGroup>
      </Objects>
    </PublishDatabaseSettings>
  </PropertyGroup>
  <ItemGroup>
    <MSDeployParameterValue Include="$(DeployParameterPrefix)DefaultConnection-Web.config Connection String" />
  </ItemGroup>
  <ItemGroup>
    <MsDeploySkipRules Include="SkipDownloadsFiles">
      <!--<SkipAction>Delete</SkipAction>-->
      <ObjectName>filePath</ObjectName>
      <AbsolutePath>.*\\Content\\UserPictures\\.*$</AbsolutePath>
      <XPath>
      </XPath>
    </MsDeploySkipRules>
    <MsDeploySkipRules Include="SkipDownloadsFolder">
      <!--<SkipAction>Delete</SkipAction>-->
      <ObjectName>dirPath</ObjectName>
      <AbsolutePath>.*\\Content\\UserPictures\\.*$</AbsolutePath>
      <XPath>
      </XPath>
    </MsDeploySkipRules>
  </ItemGroup>
</Project>

@matijagrcic
Copy link
Author

Just tried your solution but it didn't work ;(

I get the

Web deployment task failed. An error occurred when the request was processed on the remote computer.
An error was encountered when processing operation 'Delete Directory' on 'UserPictures'.
I/O error occurred.

Note that in your publish profile you use
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>

while i want this to be

false

so i have used

<UseMsDeployExe>true</UseMsDeployExe>

which allows <SkipAction>Delete</SkipAction> to be used but i suspect that this causes VS Publish preview window and output window to not show any info.

Summary

My solution is working but i would really like Preview window and output window to show detailed info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment