Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get msbuild to deploy clean app remotely

We are using msbuild to deploy an ASP.NET MVC application to a few different servers. However, msbuild does not appear to delete the remote application folder first (it just seems to update files). Our msbuild command-line looks like this:

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe" OurWebProject.csproj /P:BaseIntermediateOutputPath=c:\temp\tempfolder\ /P:Configuration=Release /P:DeployOnBuild=True /P:DeployTarget=MSDeployPublish /P:MsDeployServiceUrl=https://192.168.0.83:8172/MsDeploy.axd /P:AllowUntrustedCertificate=True /P:MSDeployPublishMethod=WMSvc /P:CreatePackageOnPublish=True /P:UserName=ARemoteWebDeployUser /P:Password=SomePassword

Is msbuild really 'smart' enough to sync the files, eliminating the need for a clean deployment each time? If not, is there an easy way to have the files deleted first?

We are using web.config transforms, so the web.config is rebuilt/redeployed every time (a good thing, since we want the app pool to restart on each deploy).

like image 943
Beep beep Avatar asked Nov 05 '22 18:11

Beep beep


1 Answers

I'm not sure if there are some specific options to msbuild command, but maybe you could add a target to your project? You could create:

<Target Name=CleanServerFolders>
  <Exec Command="psexec \\$(serverIP) -u $(serverUserName) -p $(serverUserPassword) del $(projectFolderOnServer)"
</Target>

If you don't know PsExec, look here: http://technet.microsoft.com/en-us/sysinternals/bb897553 . It's a lightweight tool from Microsoft, probably the best option to run commands on server. And then modify your msbuild command to call this target (but then you need to specify all other default targets in this command):

msbuild.exe /t:Build,CleanServerFolders,Deploy ...etc

Eventually you can add a post build events to your project file(s).

<Project>
  ...
  <Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" />
  <Target Name="AfterBuild"><CallTarget Targets="CleanServerFolders"/></Target>
</Project>

Of course Microsoft.VisualBasic.targets is a file for .vbproj projects. If you're using c#, then try Microsoft.CSharp.targets (better check the name on MSDN)

like image 90
Damian Zarębski Avatar answered Nov 13 '22 21:11

Damian Zarębski