An Azure Web Job could be a simple command line program. Creating such a piece of software in Visual Studio is more than simple. To deploy the program as a Web Job in a Web App in Azure, we just need a zip-file with the content of the bin\release-folder. To automate the creation of this step to prepare the deployment package, we just need a simple PowerShell script and a post-build event in Visual Studio.

The PowerShell script will look like this:

param (

Write-Host "Path: $Path"
Write-Host "DestinationPath: $DestinationPath"
Write-Host "ZipFile: $ZipFile"

If ((Test-Path $DestinationPath) -eq $false)
	Write-Host "Create path $DestinationPath"

	New-Item -ItemType Directory -Path $DestinationPath | Out-Null

Compress-Archive -Path $Path -DestinationPath $DestinationPath\$ZipFile -Force

Write-Host -ForegroundColor Green "Done."

Place the PowerShell script to the root folder of the project in Visual Studio.

The post-build command line will just call this script to create the package and store it in a folder in the project.

To make copy & paste easier, the post-build command line (do not copy the hash sign, just the single line of text):

if $(ConfigurationName)==Release (PowerShell -Command "..\..\CreateDeploymentPackage.ps1 -Path '$(TargetDir)*.*' -DestinationPath '$(ProjectDir)ZipPackage' -ZipFile $(TargetName).zip" )

The zip-file for the deployment to the Web Job in Azure will be stored in a sub-folder of the project. Just grab this file and use another PowerShell script or the manual way to deploy the Web Job.

That’s it.