/ Devops

Automate your WebDeploy to Azure with PS script


It's easy to publish ASP.Net MVC web app from VS. But when you need to publish several projects twice a day (continious deployment) it's became pain in the ass.

Visual Studio publishing dialog is really slow, and hangs-up often. You need from 20-40 minutes to publish a solution with several projects.

Ofcourse, you can configure Octopus or TeamCity, set-up a dedicated build server, but for me it was an overkill. So I decided to create a simple powershell script.

In this article I'll describe deployment of ASP.Net solution with several projects (including WebJobs) to Azure.


  • You have a working deployment from VS deploy dialog
  • You have installed latest version of WebJobs Publish

Deploy from PowerShell

Firts of all, you should allow executing powershell scripts on your machine
Set-ExecutionPolicy RemoteSigned

To publish from PS we'll use msbuild. It's behavior easy to configure. You just need to pass a few parameters and it'll do the same things as you do in GUI.

Run MsBuild and publish project

& $pathToMsBuild ` #path to msbuild, see gist below
$projectPath ` #path to your project .csproj file
		/p:DeployOnBuild=true ` 
		/p:PublishProfile="$profileName" ` #profile name you can grab from VS publish dialog
		/p:SolutionDir="$solutionDir" ` #path to folder where .sln file located
		/p:Password=$password ` #password from .PublishSettings
		/p:IncludeSetAclProviderOnDestination=False #need to publish correctly to Azure, because Azure FS don't recognize ACL 

Publishing WebJob

Good news, with WebJobs Publish package, publishing of webjobs will work the same. Magic!

All together

To generalize a bit things, i writed a powershell script which read all information from .PublishSettings file and do publish.

You can call this script to publish any project from your solution.


# publish MyProject
& ("./PublishScripts/publishProject") ` #path to script
	$projectConfiguration `#path to .PublishSettings configuration file
	$portalProfileName ` #name of profile from VS dialog (e.g "MyProject - WebDeploy")
	"MyProject" #project name

Now deployment of my solution takes seconds, I need only run one PS script to deploy all projects.

Isn't it cool?