Share via


Migrating and Deploying a Simple Cloud App: Part 4 - Creating the Cloud Solution

Deploying-a-Simple-Application_thumb

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

  1. Fire up Visual Studio 2010, then from the File menu, select New, and then Project.

  2. 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.

  3. Enter NerdDinnerCloud as the solution name

  4. If it’s not already, check off Create directory for solution.

  5. Click OK to create the solution and project.

    image

  6. 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.

  7. 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.

    image

  8. Click OK.

  9. 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.

    image 

    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.

image

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

  1. 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.

  2. Click OK to confirm the deletion.

  3. Right-mouse click on the solution in the Solution Explorer, select Add, and then select Existing Project.

  4. Browse to the directory where you unzipped the Nerd Dinner package, select the NerdDinner project and click Open.

    image

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.

image

Notice how the Cloud project is now showing that there are no projects associated with the Cloud roles. Let’s fix that.

  1. Right mouse click on No project associated… under Roles, select Associate With, and then select Web Role Project In Solution…

  2. Click on NerdDinner.

    image

    The error should now be resolved.

Checking and Updating the Solution

  1. 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.

  2. Expand the References node, select System.Web.Mvc, and open the Properties pane. Check the Copy Local attribute. It should be set to True.

    image

  3. 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.

  4. 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.

    image

Updating the Connection Strings

  1. Flip back to the Windows Azure Management Portal.

  2. From the Databases screen, click on the NerdDinner database we provisioned in part 1.

  3. 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.

    image_thumb[2]

  4. Highlight the text under the heading ADO.NET and then press CTRL+C

    image_thumb[5]

  5. Flip back to Visual Studio and open ConnectionStrings.config from the Solution Explorer.

  6. In the ApplicationServices connection string attribute, delete everything between the quotes after connectionString= . Place your cursor between the quotes and paste the connection string.

  7. 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:

    image_thumb[15]

  8. Do the same for the NerdDinnerEntities connection string. The final connection string should look like this:

    image_thumb[14]

  9. 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.