



I’ve recently been working on a little side project – a site called “azure101.com”. I originally created it as a web application project and now decided I wanted to show some friends. I thought about hosting it on a beta sub domain (i.e. beta.azure101.com) but then it occurred to me that I should put it on Azure instead. This meant I needed to create a cloud service project and affiliate my web app with it.
This is a pretty easy thing to achieve if your app stands alone and doesn’t use any databases, etc (which is definitely the case here) so I thought I’d share the few simple steps needed to achieve this.
First you need to add a cloud service project to your solution. In the ‘Add New Project’ dialog, ensure you select the ‘Blank Cloud Service’ option:
This adds the cloud service to your solution – I named mine ‘azure101CloudService’. You will notice only the one project is added to your solution and that the ‘Roles’ node is empty. We need to affiliate our existing web app to the cloud service as a ‘Web Role’. But when we right click the node we don’t get the option to add an existing web project in our solution – its disabled.
This is because the cloud service project does not yet recognize our web application as a valid cloud web role. To fix this we need to make a change to the project file directly.
Editing a project file is not as scary as it sounds. All project files in Visual Studio are built on MSBuild and are friendly looking XML files that follow a specific schema. If you’re familiar with NAnt then you’ll be able to pickup MSBuild in no time, however in our case the change is very simple and you don’t need knowledge of MSBuild to make this change.
First we need to unload our web application project file, and then edit it. I have certain power tools installed that let me unload and edit in one click – “Edit Project File”. If you don’t have this option, simply choose the “Unload” option and then the “Edit” option. It should be pretty obvious where to click. You will notice that when unloaded you will not be able to see any of the files in your project. This is perfectly normal.
In the project file you will see a bunch of XML and we’re looking for a node that’s called ‘PropertyGroup’ (there will be more than 1, just use the first one in the file). This essentially is a list of variables that the build script will use. We are going to add a new variable (property) called ‘RoleType’. As the last element in the PropertyGroup, add this code:
<RoleType>Web</RoleType>
This extra property is what marks a project as being a web role for a cloud service. Save your change and close the file. You can now right click on your web project and reload it. This should restore it to its original state. You can still use the project exactly as before – run it by itself to see what I mean.
Now we can attempt to affiliate the web project with our cloud service. Go back to the Roles node and right click again. This time you can see that the option to add a ‘Web Role Project in solution’ is available. When selected, we then get presented with a dialog where we can choose which project to add – our web application is an option. We select it and when all is done, our web app now appears as a role in our project. ![]()
![]()
So there you go! Quick and easy. The important thing now is that you can either run the web app standalone, or you can run it on your local development fabric, OR you can deploy it to Windows Azure.










More Options ...

Categories
Tag Cloud
Blog RSS
Comments RSS

Void
Life
Earth
Wind « Default
Water
Fire
Light 
10:26 pm - March 7th, 2010
[...] applications, configuration can work exactly the same as standard .Net applications. If you have a web role, then you have a web.config. And if you have a worker role, you get an app.config. This allows you [...]
7:30 pm - January 20th, 2012
Thanks for this tip, really helped me with bringing my existing Windows Service into the Azure Worker Role project. Cool looking site, by the way!
7:01 am - February 18th, 2013
Luella…
Above The Cloud » Blog Archive » Converting A Web App Into An Azure Cloud Service Web Role…
3:46 pm - May 4th, 2013
go here…
Above The Cloud » Blog Archive » Converting A Web App Into An Azure Cloud Service Web Role…