Exercise 3: Using Visual Studio to Publish ApplicationsPreviously, you learnt how to deploy applications to Windows Azure using the Management Portal and a set of PowerShell cmdlets. If you are a developer, you may find it more convenient during your development cycle to deploy your applications directly from Visual Studio. The first time you publish a service to Windows Azure using Visual Studio, you need to create the necessary credentials to access your account. This involves generating a self-signed certificate that you can upload to the Windows Azure Management Portal. In Exercise 2 of this lab, you followed a similar procedure when you created a certificate using the makecert utility. Visual Studio streamlines this process and allows you to generate the certificate by specifying the necessary information by way of its UI. Once you set up your account information in Visual Studio, you can publish your current solution in the background with only a few mouse clicks. In this exercise, you set up the credentials to authenticate with the Windows Azure Management Service and then publish the MyTodo application from Visual Studio. Task 1 – Preparing the Solution for PublishWhen you publish your service using Visual Studio, the Windows Azure Tools upload the service package and then automatically start it. You will not have a chance to update the configuration settings before the service starts. Therefore, you must configure all the necessary settings before you publish the service. In this task, you update the storage connection strings to point to your Windows Azure storage account. - Open Microsoft Visual Studio 2010 as administrator. To do this, in Start | All Programs | Microsoft Visual Studio 2010, right-click the Microsoft Visual Studio 2010 shortcut and choose Run as Administrator.
- In the File menu, choose Open and then Project/Solution. In the Open Project dialog, browse to Ex3-DeployingWithVisualStudio\Begin in the Source folder of the lab, select MyTodo.sln in the folder for the language of your preference (Visual C# or Visual Basic) and click Open.
- In Solution Explorer, expand the Roles node inside the MyTodo cloud project and then double-click the MyTodo.WebUx role.
- In the MyTodo.WebUx [Role] window, switch to the Settings tab and configure the necessary Azure Storage account details replacing [YOUR_ACCOUNT_NAME] with the name of your storage account and [YOUR_ACCOUNT_KEY] with the shared key. Do this for both DataConnectionString and Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString settings. These are the same values that you used in previous exercises to configure the application.
- Press CTRL + S to save your changes.
Task 2 – Generating a Self-Signed Certificate in Visual StudioIn this task, you create a second management certificate using Visual Studio—you created the first one earlier using a command line tool—and then upload it to the Windows Azure Management Portal. - If it is not already opened, launch Microsoft Visual Studio 2010 as administrator. To do this, in Start | All Programs | Microsoft Visual Studio 2010, right-click the Microsoft Visual Studio 2010 shortcut and choose Run as administrator.
- In the File menu, choose Open and then Project/Solution. In the Open Project dialog, browse to Ex3-DeployingWithVisualStudio\Begin in the Source folder of the lab, select MyTodo.sln in the folder for the language of your preference (Visual C# or Visual Basic) and click Open.
This is the same solution deployed earlier except for a legend in its footer area to indicate that it was deployed using Visual Studio. - In Solution Explorer, right-click the MyTodo cloud project and select Publish.
- It will prompt the Publish Windows Azure Application dialog. To publish an application, you first need to create the necessary credentials to access your Windows Azure account. To add a new set of credentials to your configuration, expand the Subscription drop down list and select Manage. If you have already added your credentials, chose them and skip this task.
.png)
Figure 47Adding Subscription’s credentials in Visual Studio - It will prompt a dialog to manage your Windows Azure authentication settings. Click New to define you authentication settings.
.png)
Figure 48Adding Authentication Settings - To create the credentials, you require a certificate. If Visual Studio cannot find a suitable certificate in your personal certificate store, it will prompt you to create a new one; otherwise, in the Windows Azure Project Management Authentication dialog, expand the drop down list labeled Create or select an existing certificate for authentication and then select Create.
.png)
Figure 49Creating a new certificate for authentication The drop down list contains all the certificates that are suitable for authentication with the Azure Management API. This list includes the certificate you created earlier, during the PowerShell deployment exercise. Nevertheless, in this exercise, you create a new certificate to walk through the procedure required to generate certificates in Visual Studio. - In the Create Certificate dialog, enter a suitable name for the certificate, for example, AzureMgmtVS, and then click OK.
.png)
Figure 50Creating a new management certificate - Back in the Windows Azure Project Management Authentication dialog, ensure that the newly created certificate is selected. Notice that the issuer for this certificate is the Windows Azure Tools.
.png)
Figure 51Selecting a certificate for the credentials - Now, click the link labeled Copy the full path. This copies the path of the certificate public key file to the clipboard.
.png)
Figure 52Copying the path of the certificate public key file to the clipboard Visual Studio stores the public key file for the certificate it generates in a temporary folder inside your local data directory. - Click OK to dismiss the confirmation message box and then save the path in the clipboard to a safe location. You will need this value shortly, when you upload the certificate to the management portal.
.png)
Figure 53Confirmation that the file path was copied to the clipboard successfully - Next, click the link labeled Windows Azure Portal to open a browser window and navigate to the Windows Azure Management Portal.
.png)
Figure 54Opening the Developer Portal in your browser - At the Management Portal, sign in and then upload the certificate that you generated in Visual Studio using the same procedure described in Task 2 of the previous exercise. Refer to that section of the document for detailed instructions.
- If you did not keep a record of the Subscription ID of your account, make a note of this value from the Account page now. You will require it for the next step.
- At the API Certificates page, when selecting a certificate file from your local storage, make sure to use the path that you copied earlier from your clipboard to specify the certificate public key file to upload.
- To complete the setup of your credentials, switch back to the Windows Azure Project Management Authentication dialog, enter your subscription ID and a name to identify the credentials and then click OK.
.png)
Figure 55Completing the credential setup procedure - After you confirm the creation of the new credentials, Visual Studio uses them to access the management service to verify that the information that you provided is valid and notifies you if authentication fails. If this occurs, verify the information that you entered and then re-attempt the operation once again.
.png)
Figure 56Authentication failure while accessing the management service - In the Windows Azure Project Management Settings dialog, you will see the recently created Authentication setting. Click Close to return to the Publish Wizard. You will continue with the publishing process in the next task.
.png)
Figure 57Managing Authentication settings
Task 3 – Publishing a Service with the Windows Azure ToolsIn the previous task, you configured a set of credentials that provide access to your Windows Azure account. Visual Studio saves this information and allows you to reuse the credentials whenever you need to publish a service, without requiring you to enter your credentials again. In this task, you use these credentials to publish the MyTODO application directly from Visual Studio. - In the Publish Windows Azure Application dialog, select the credentials that you created in the previous task and click Next.
.png)
- In the Common Settings tab, notice that the dialog populates the drop down list labeled Hosted Service with the information for all the services configured in your Windows Azure account. Select the hosted service in this list where you wish to deploy the application.
- Make sure the Environment is set to Production and the Build Configuration to Release. Also, set the Service Configuration with default value.
.png)
Figure 59Deployment Common Settings - Click Advanced Settings tab. Update the Deployment Label to MyTodo and check the check box labeled Append date and time to identify the deployment in the Developer Portal UI.
- Like with the Hosted Services, the dialog populates the drop down list labeled Storage account with all the storage services that you have configured in your Windows Azure account. To publish a service, Visual Studio first uploads the service package to Azure storage, and then publish the service from there. Select the storage service that you wish to use for this purpose and click Next.
.png)
Figure 60Deployment Advanced Settings Although this is not covered in this lab, the IntelliTrace option enables you to capture detailed trace logs of your running service in the cloud that you can download to your desktop to perform historical debugging. This can be invaluable when troubleshooting issues that occur during role start up. Note that IntelliTrace requires the .NET Framework 4 and it is only available in Visual Studio Ultimate edition. - Review the Summary information. If everything is OK, click Publish to start the deployment process.
.png)
Figure 61Starting Deployment At the top of the dialog, you will find a Target Profile drop down list. Once you configured your deployment settings, you can save them as a new profile and use it later without having to complete all the fields again. - If the slot that you chose is already occupied by a previous deployment, Visual Studio warns you and asks for confirmation before it replaces it. Click Replace if you are certain that the current deployment is no longer needed and can be overwritten. Otherwise, click Cancel and repeat the operation choosing a different deployment slot.
.png)
Figure 62Overwriting an existing deployment - After you start a deployment, you can examine the Windows Azure activity log window to determine the status of the operation. If this window is not visible, in the View menu, point to Other Windows, and then select Windows Azure Activity Log.
- By default, the log shows a descriptive message and a progress bar to indicate the status of the deployment operation.
.png)
Figure 63Viewing summary information in the Windows Azure activity log - To view detailed information about the deployment operation in progress, double-click the green arrow on the left side of the activity log entry.
Notice that the additional information provided includes the deployment slot, Production or Staging, the Website URL, the Deployment ID, and a History log that shows state changes, including the time when each change occurred. .png)
Figure 64Viewing detailed information about a deployment operation - Wait for the deployment operation to complete, which may take several minutes. While this is happening, you can examine the History panel on the right side to determine the status of the deployment. For a successful deployment, it should resemble the following sequence.
.png)
Figure 65Deployment operation history log - Once the deployment operation is complete, in the Windows Azure Activity Log, click the Website URL link for the completed operation to open the application in your browser and ensure that it is working properly. Notice the legend in the copyright notice at the bottom of the page indicating that this is the version that you deployed with Visual Studio.
.png)
Figure 66Running the application deployed with Visual Studio
| |