in Blog

Make Existing Projects Run in Azure

Disclaimer: This is not a tutorial on how to take an existing project and make it ‘just work’ in Azure. Depending on your existing project it may either be as easy as described below, or so painful that it’s not worth it. The goal of this post is simply to show how to make projects compatible with the Azure development fabric.

So you’ve got an existing project and are experimenting with making it run on the Azure platform. Do you.

A) Create new Azure projects and meticulously copy your code over?

B) Throw your hands up in defeat and tell your boss it’s too much work?

C) Add a few snippets of code to your existing projects and be a hero?

As it turns out, C is the correct answer! In the case of either a web application or a class library, you can easily turn them into web roles and worker roles, respectively. In order to do this, simply unload the project and add the appropriate XML to the project.

To make a web application project (including ASP.NET MVC) able to run as a web role, add the following.

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

To make a class library project able to run as a worker role add the following.

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Once you’ve made these changes and reloaded the project, you should be able to associate your cloud service project with an existing web or worker role!

Unload Project

Unload Project

Edit Project

Edit Project

Editing Project

Add XML

Reload Project

Reload Project

Associate Role

Associate Project

A Few More Tricks

Copy LocalAs I was working on this post I came across a few more tricks and undocumented nuances that cost me an unfortunate amount of time trying to figure out.

  • In order to run an ASP.NET MVC application under Azure, you’ll need to copy the System.Web.Mvc assembly local. This can easily be accomplished from the properties pane.
  • In web applications, you can not work with the RoleManager within Application_Start (see the remarks after the jump).
  • While you can make any class library a worker role, the development fabric will crash & burn if you do not have exactly one class in that assembly the derives from RoleEntryPoint.
  • Related Content by Tag