When you install Windows Azure Tools for Visual Studio, you only get a project template for an ASP.Net Web Role. In this post I’ll talk about how to create a new ASP.Net MVC Web Role or move an existing ASP.Net MVC Application to Windows Azure.
There are 2 ways to do this:
The following steps apply both for creating a new ASP.Net MVC application and to moving an existing ASP.Net MVC application to Windows Azure.
1. Create an empty ASP.Net MVC Application (with or without a test project), or make sure you have an existing ASP.Net MVC application that you want to move to the Windows Azure.
2. Close this solution and create a new Blank Cloud Service. Make sure you start Visual Studio as an administrator because working with the Development Fabric requires that.
3. Add an existing project to the cloud service and select the ASP.Net MVC Application you have created earlier.
4. Right click the ASP.Net MVC project and select Unload Project.
5. When the project is unloaded, right click it and edit the project file.
6. The project file opens in the XML Editor.
<Project ToolsVersion="3.5" DefaultTargets="Build" ...>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Inside the PropertyGroup Element, add the RoleType element and mark this ASP.Net MVC project as a Web Role.
7. Close this project file, and reload the project.
8. Since the ASP.Net MVC now runs on the Windows Azure Service Hosting environment and will probably use its services – add a reference to Microsoft.ServiceHosting.ServiceRuntime.dll.
9. Right click the Roles node in the project tree, and add a Web Role Project in the solution. Select the ASP.Net MVC project from the project list.
Now the ASP.Net MVC project is shown as a Web Role.
10. Since the Windows Azure provides us only with the default .Net Framework 3.5 SP1 assemblies, we must make sure we also copy the ASP.Net MVC Assemblies to the cloud. To do this, right click on each of the following references of the ASP.Net MVC application, and set the Copy Local property to True:
That’s it. You can run the application to make sure that it is running on the Development Fabric.
Creating an ASP.Net MVC Web Role using a Project Template
Thanks to a great word done by the community, we can use a project template to do all the above steps for us. Here’s how to do this:
1. Download the project template from Codeplex at http://c4mvc.codeplex.com/.
2. Create a new project and select the Azure ASP.Net MVC template in the Community for MVC category.
This creates a new Cloud Service for Windows Azure with ASP.Net MVC Application as a Web Role.