29

I am using the MSBuild runner in Team city to build and deploy my project to a staging environment. Everything works perfectly except for the fact that it keeps removing my repository folder located in the root of the project.

In Visual Studio 2010 there is a check box in the publish profile dialog that says "Leave extra files on destination (do not delete)"

Is there a way to accomplish the same thing with MSBuild?

<Target Name="Deploy" DependsOnTargets="Build;Test">
        <MSBuild Projects="MyProject.sln" Properties="Configuration=$(Configuration); username=username; password=password; DeployOnBuild=True; DeployTarget=MSDeployPublish; MSDeployPublishMethod=WMSVC; MSDeployServiceUrl=https://DEVWEB01:8172/MsDeploy.axd; DeployIISAppPath=MyProject.$(Configuration); AllowUntrustedCertificate=True;"/>
</Target>
Jeremy Seekamp
  • 2,746
  • 1
  • 22
  • 25

1 Answers1

52

Found the answer!

All you need to do is add the following property to the Properties attribute:

SkipExtraFilesOnServer=True;

Jeremy Seekamp
  • 2,746
  • 1
  • 22
  • 25
  • 4
    Yikes I just spent over a day trying to figure out how to make this work using -enableRule:DoNotDeleteRule (a parameter that I can pass in to MSDEPLOY.exe) but TFS would not have it. I simply added /p:SkipExtraFilesOnServer=True to the MSBuildArguments in the TFS build definition, and it worked! Thanks a lot :-) – Philippe Aug 31 '11 at 12:08
  • Do you know if this config parameter can also be set by environment variables? In teamcity, I currently use environment variables for things like Configuration and deploy path.. these seem to be written into the SetParameters.xml but i dont know why or when.. – diegohb Mar 22 '13 at 18:58
  • 7
    Is there a way to add this per folder instead of globally? – Mike Cole Aug 16 '13 at 15:44
  • @MikeCole Not to my knowledge, unless you're breaking down your MSDeploy sync folder by folder. – efisher Dec 18 '13 at 19:55
  • somehow web deploy ignores this when added in msbuild properties – spankmaster79 Jun 25 '15 at 14:10
  • 1
    I was using Bamboo and was struggling with this, there are a lot of answers that basically say the same and that also confuses MSBuild and MSDeploy. So the important part here is to use /p:SkipExtraFilesOnServer=True; parameter for the MSBuild.exe part and then use the -EnableRule:DoNotDeleteRule when calling MSDeploy.exe and those two pieces together will prevent the files from being delete on the target server. – a4bike Aug 10 '16 at 21:55