How do I keep MSDeploy from deleting extra folders in my project?
Asked Answered
T

1

30

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>
Tswana answered 23/7, 2010 at 18:32 Comment(0)
T
53

Found the answer!

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

SkipExtraFilesOnServer=True;

Tswana answered 23/7, 2010 at 18:39 Comment(6)
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 :-)Lecompte
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..Franciscafranciscan
Is there a way to add this per folder instead of globally?Tout
@MikeCole Not to my knowledge, unless you're breaking down your MSDeploy sync folder by folder.Walcott
somehow web deploy ignores this when added in msbuild propertiesRoy
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.Brubeck

© 2022 - 2024 — McMap. All rights reserved.