Web Deploy ignores SkipExtraFilesOnServer set by MSBuild

3.2k views Asked by At

I'm using MSBuild to create a Web Deploy Package on our CruiseControl Server to Deploy our web applications. On deployment everything not in the package will be deleted on our servers.

I tried the option SkipExtraFilesOnServer option set to true. But it is ignored by Web Deploy

<Target Name="CreateDeploymentPackage">
    <MSBuild Projects="$(Web)" Targets="Package"
      properties="Platform=$(Platform);
      Configuration=$(Configuration);
      DeployOnBuild=False;
      DeployTarget=Package;
      SkipExtraFilesOnServer=True;
      MSDeployUseChecksum=True;
      PackageLocation=$(DeployDirectory)\_PublishedWebsites\DeployPackage\$(CurrentProject).zip;
      PackageAsSingleFile=True;
      _PackageTempDir=$(PackageOutputDir)\temp;">
    </MSBuild>
</Target>

Why is this not working? Every documentation I find says it should.

2

There are 2 answers

5
Sayed Ibrahim Hashimi On BEST ANSWER

I'm not following you 100% but, I think I understand what's happening here. Here is my understanding of your situation.

You've configured your build server to do the following.

  1. Build a web deploy package using msbuild.exe
  2. You've set SkipExtraFilesOnServer=true when creating the package
  3. Publish the web deploy package using msdeploy.exe

The issue that you are likely running into is when the package is published to the server. When pass SkipExtraFilesOnServer=true is translated to the msdeploy option -enableRule:DoNotDeleteRule. Which is applied (and relevant) when publishing to the package in your case. Now you need to ensure that option is set when the package is published to the server. That option is not embedded in the package in anyway.

0
Markus Jarderot On

You can affect the generated .publish.cmd file by setting different properties. If you want to translate the SkipExtraFilesOnServer property into -enableRule:DotNotDeleteRule, you can add this to your .csproj-file:

<PropertyGroup>
  <_GenerateSampleDeployScript_AfterSet_Destination
      Condition="$(SkipExtraFilesOnServer) == 'True'">
    set _MsDeployAdditionalFlags=%_MsDeployAdditionalFlags% -enableRule:DoNotDeleteRule
  </_GenerateSampleDeployScript_AfterSet_Destination>
</PropertyGroup>

It will add the -enableRule:DoNotDeleteRule argument to msdeply, whenever the package is generated with the SkipExtraFilesOnServer property set to True.