I finally managed to get it working using MSDeploy.exe. I found out that running msbuild with "/p:DeployOnBuild=true", but without "/p:PublishProfile" doesn't actually publish mobile service, but creates the folder with contents, that can be published with msdeploy.
Steps which should be followed to publish mobile service using msdeploy:
Within building process:
- Add /p:DeployOnBuild=true to msbuild command that builds mobile service
- The publish folder is created in obj\Release\Package. This folder contains PackageTmp folder as well as a few files (.cmd, .xml, .zip) which are supposed to be used during publishing. However I couldn't get it working with these files. In my case PackageTmp folder was what I needed and I copied this folder to the output of build process.
Within publishing process:
- (only once) Download publish profile (.publishsettings file) for the mobile service from Azure Management portal (link available on Dashboard tab)
- Run the batch which runs msdeploy.exe:
@echo off
if "%MSDeployPath%" == "" (
for /F "usebackq tokens=1,2,*" %%h in (`reg query "HKLM\SOFTWARE\Microsoft\IIS Extensions\MSDeploy" /s ^| findstr -i "InstallPath"`) do (
if /I "%%h" == "InstallPath" (
if /I "%%i" == "REG_SZ" (
if not "%%j" == "" (
if "%%~dpj" == "%%j" (
set MSDeployPath=%%j
))))))
"%MSDeployPath%"\msdeploy.exe -verb:sync -source:contentPath=<path_to_PackageTmp_folder> -dest:ContentPath=<mobile_service_site>,PublishSettings=<path_to_downloaded_publishsettings_file>,AuthType='Basic' -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension
Alternatively it is possible to compress contents of the mentioned PackageTmp folder into a zip and change the publish line to:
"%MSDeployPath%"\msdeploy.exe -verb:sync -source:package=<path_to_zip_file> -dest:ContentPath=<mobile_service_site>,PublishSettings=<path_to_downloaded_publishsettings_file>,AuthType='Basic' -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension
A few times I had to restart mobile service after publishing. It can be easily accomplished with Azure CLI.
I hope the above helps someone, who would like to automate mobile service deployment process :-)
The article which helped me to get it all done: Azure Mobile Service deployment with Team City part 4. Deploying Azure Mobile Services