Deploying .NET-based Web Jobs to Windows Azure

I was very excited when I learnt about the new Web Jobs preview feature on Windows Azure Websites. The ability to run separate background processing jobs alongside a web application is one of the critical features of any complex web application.

Amit Apple has a really good article covering the various deployment options for Web Jobs which I would recommend reading. If you are deploying a Node.js (or other script-based) application the convention based deployment model works very well but you might be wondering how you can streamline the deployment of a compiled binary along with your web application.

Managing Web Job Files

Let’s say that you have a .NET solution consisting of an ASP.NET web app and a simple console application. What we want to do is execute the console application as a Web Job, pretty straight forward.

ProjectStructure

In order to deploy a .NET-based Web Job you need to first compile your .NET code and then drop the executable or its dependencies into the App_Data/jobs directory structure. You could manually compile the files and then copy them into the directory but you are likely going to want to do this 100s of times as you build out the jobs, so you need something a little bit more productive.

One approach that you can take is to edit the *.csproj file for the web job console application itself. If you right mouse click on the console app and select Unload Project, then again to edit the file you can scroll down the bottom and update the AfterBuild build target as in the SimpleWebJob.csproj example below (contents removed to keep the file brief).

CsprojEdits

In the sample above I’m pushing the executable into the executable into the appropriate folder in the ASP.NET project. A more complete example might include copying configuration files and dependencies as well. You also need to make sure that you include the files that are being copied in the ASP.NET project itself so that they can get pushed up to the server.

Even though the web app isn’t directly referencing the console application, the console app is actually a dependency of a web-app, so you might want to do is right click on the web app project and select Build Dependencies | Project Dependencies to explicitly specify that SimpleWebApp (in my example) depends on SimpleWebJob.

ProjectDependencies

Once this is done you should be able to just publish your project from Visual Studio and the web jobs should automatically be created.

Room for Improvement

The Web Job feature is still in preview so I think it is fair to expect some further evolution in what you can do with Web Jobs. As a .NET developer I hope that the deployment process can be streamlined somewhat for .NET-based executables. Another thing that I would like to see is the ability to deploy a *.webjob file along with everything else in the directory which is used to provide additional metadata about the web job (such as being specific about what file is the entry point along with scheduling data).

Overall though I think it is a welcome improvement to Windows Azure Websites!

3 thoughts on “Deploying .NET-based Web Jobs to Windows Azure

  1. Pingback: Remotely Debugging Web Jobs on Windows Azure Websites | Mitch Denny

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s