Migrating and Deploying a Simple Cloud App: Part 4 - Creating the Cloud Solution
If you’ve started reading from this post, you’ll need to go through the previous parts of this series before going starting this one:
Introduction
Part 1: Setting Up a SQL Azure Server and Database
Part 2: Scripting the On-Premise Database for SQL Azure
Part 3: Executing the Scripts on the SQL Azure Database
With the database deployed, we can now focus our attention on the application itself. In this part, we’ll create the Cloud solution project in Visual Studio 2010 and migrate our on-premise application code to our new Cloud solution.
Creating a Cloud Solution
Fire up Visual Studio 2010, then from the File menu, select New, and then Project.
With the Windows Azure SDK installed, you’ll now have a Cloud template category in the Installed Templates list. From the Cloud templates, select Windows Azure Project.
Enter NerdDinnerCloud as the solution name.
If it’s not already, check off Create directory for solution.
Click OK to create the solution and project.
The New Windows Azure Project screen that comes up now will be new to you. This is where you select the different instances that you’re going to need Windows Azure to provision in order to run your solution. Since Nerd Dinner is an MVC web application, let’s add an ASP.NET MVC 2 Web Role. Click on the role and then the > to add it to the solution.
As good practice, you should name the roles that you add to the solution so that they can easily be identified. Select the role from the list on the right-hand side, click on the pencil icon, and enter NerdDinnerWebRole as the name.
Click OK.
Visual Studio will prompt you to create a unit test project. It’s good practice to do so, but for the purposes of this walkthrough, let’s skip this step. Select No, do not create a unit test project.
I know that I probably don't have to mention this, but all components of applications that you develop for production use should really have associated unit test projects.
Exploring the Generated Solution
Visual Studio has now gone ahead and provisioned everything we need in order to get started. Let’s have a look at the Solution Explorer.
As you can see there are two parts to Cloud projects – or two “projects” in the solution. The first project (with the blue icon) contains ServiceConfiguration.cscfg. ServiceConfiguration.cscfg, along with its definition file ServiceDefinition.csdef, specify the number of role instances to deploy for each role in the solution, the values of any configuration settings, and the thumbprints for any certificates associated with a role . The second project is the standard project that you would create for an on-premise solution.
For a deeper dive on the service configuration and service definition files, read through:
Defining the Settings for an Application
Configuring an Application
Migrating the Existing Project
The Nerd Dinner solution already contains a web project, so we won’t need the one provisioned by Visual Studio. Go ahead and remove the project. Right-mouse click on the project and click on Remove.
Click OK to confirm the deletion.
Right-mouse click on the solution in the Solution Explorer, select Add, and then select Existing Project.
Browse to the directory where you unzipped the Nerd Dinner package, select the NerdDinner project and click Open.
Associating the Existing Project with a Cloud Role
With our existing Nerd Dinner project now imported, let’s have another look at the Solution Explorer.
Notice how the Cloud project is now showing that there are no projects associated with the Cloud roles. Let’s fix that.
Right mouse click on No project associated… under Roles, select Associate With, and then select Web Role Project In Solution…
Click on NerdDinner.
The error should now be resolved.
Checking and Updating the Solution
We need to make sure that the System.Web.Mvc assembly will be copied to the local bin directory of the application.
The VMs within Windows Azure only support the files that ship with the .NET framework. Setting “Copy Local” to True in the properties of each additional assembly will ensure that it is included in the deployment package.
Expand the References node, select System.Web.Mvc, and open the Properties pane. Check the Copy Local attribute. It should be set to True.
When Nerd Dinner was originally packaged, the SQL MDF files were added to the solution. In order to reduce the space used by the web role, let’s delete those files. From the Solution Explorer, expand the App_Data folder and delete NerdDinner.mdf.
We need to make sure that the additional configuration file in the NerdDinner project is also included in the deployment package. From the Solution Explorer, click on ConnectionStrings.config, open the Properties pane,and have a look at the Build Action attribute. It should be set to Content.
Updating the Connection Strings
Flip back to the Windows Azure Management Portal.
From the Databases screen, click on the NerdDinner database we provisioned in part 1.
The Windows Azure Management Portal will actually generate the connection string for you. In the Properties pane, click on the … button beside View under Connection Strings.
Highlight the text under the heading ADO.NET and then press CTRL+C.
Flip back to Visual Studio and open ConnectionStrings.config from the Solution Explorer.
In the ApplicationServices connection string attribute, delete everything between the quotes after connectionString= . Place your cursor between the quotes and paste the connection string.
Find Password=mypassword and change mypassword to the password that you used when we created the database. The final connection string should look something like this:
Do the same for the NerdDinnerEntities connection string. The final connection string should look like this:
Save the configuration file.
That’s it for the connecting strings. Now let’s test the application using the local development fabric before we deploy it to Windows Azure.