Export (0) Print
Expand All

Getting Started with the Azure Tools for Visual Studio

Updated: October 16, 2013

By following this walkthrough, you can learn how to use the Windows Azure Tools for Visual Studio, which help you to be more productive when you develop a Windows Azure application. You can use these tools to run and debug the application locally before you publish it to Windows Azure. You can use the following procedures to accomplish these tasks:

The Windows Azure Tools work with several versions of Visual Studio. This walkthrough shows UI from one version of Visual Studio. You might find that the UI differs slightly from illustrations in this topic, depending on your versions of Visual Studio and the Windows Azure Tools

Installing the Windows Azure Tools for Visual Studio

This procedure assumes that you haven't yet installed the Windows Azure Tools. If you've already installed the Windows Azure Tools, start with the next procedure about how to create a Windows Azure application.

To install the Windows Azure tools

  1. To install the Windows Azure Tools, on the menu bar, choose File, New, Project. From Installed Templates choose either the Visual Basic or Visual C# node, and then choose the Cloud node that contains a project template named Get Windows Azure SDK for .NET.

    This template is only displayed in the list if you have not installed the Windows Azure Tools before on this computer.

  2. To download the tools, choose the OK button.

    A Windows Azure Tools tab is displayed.

  3. To start the download, choose the Download Windows Azure Tools button. The web installer is now displayed. Follow the instructions provided by the web installer to install the latest version of the Windows Azure Tools and the Windows Azure SDK.

    Windows Azure Tools requires Internet Information Services (IIS) version 7, 7.5, 8, or Express. To install IIS or IIS Express, use the Microsoft Web Platform Installer.

To update the template to show the Windows Azure Project template, you might have to restart Visual Studio before you can proceed with the steps in the following procedures.

Creating a Windows Azure Application

A Windows Azure application consists of roles that perform the actions required by the application. When you publish your application to Windows Azure, each role is run on a virtual machine in the cloud. For more information about how to develop a Windows Azure application, see Planning and Designing Applications for Windows Azure and Developing Applications for Windows Azure.

To create a Windows Azure application

  1. Start Visual Studio as an administrator.

  2. To create a Windows Azure project, on the menu bar, choose File, New, Project.

  3. In the C# and VB project templates that are displayed in Installed Templates, choose the Cloud template type that was updated. Choose Windows Azure Project. In the .NET Framework list, choose the target framework that you want to use.

    Create a new project
    Visual Studio 2012 and Visual Studio 2013 support both the .NET Framework 4.5 and the .NET Framework 4..

  4. In the Name text box, enter the name for your project and choose the OK button.

    The New Windows Azure Project dialog box is displayed.

    Create a new Windows Azure project.
  5. To add a web role to the solution, choose ASP.NET Web Role and then choose the right arrow. You can add multiple web and worker roles to your Windows Azure solution.

    The roles are displayed in the Windows Azure solution pane of the dialog box.

  6. To rename WebRole1 to MyWebRole, move the pointer over WebRole1and choose the pencil icon on the right side. Type the new name and then choose the Enter button. (Keyboard: Tab to move the focus to WebRole1 and press F2 to edit.)

  7. Choose the OK button. The New ASP.NET Project dialog appears. Choose Web Forms.

    Choose Web Forms.
  8. To create the new Windows Azure project, choose the OK button.

    You now have a solution with the following two projects:

    • A Windows Azure project

    • A web role that is an ASP.NET web application

    The Solution Explorer view will look similar to the following illustration:


Add Code to the Web Role Project

The following procedure adds code to the web role project. This web project adds data to blob storage and writes a diagnostics message to help you debug an application. You can then run this code locally before you publish it to Windows Azure.

To add code to the Web Role project

  1. To open default.aspx in design view, open the shortcut menu for the default.aspx file and then choose View Designer.

  2. To open the toolbox, choose the Toolbox icon. To add a button to the page, open the shortcut menu for Button in the Toolbox view and choose Copy. In the editor window for Default.aspx choose Design, then open the shortcut menu and choose Paste. To add a click event handler for the button, double-click the new button that you added to the page.

  3. In the click event handler named Button1_Click, add code that will upload some text to the blob service and add a diagnostics message. To add the required Windows Azure types, add the following using statements to default.aspx.cs:

    using Microsoft.WindowsAzure;
    using Microsoft.WindowsAzure.Storage;
    using Microsoft.WindowsAzure.ServiceRuntime;
  4. Add the following code to accomplish these tasks:

    • Create a CloudStorageAccount instance from a connection string in the configuration settings

    • Create a blob container

    • Upload a text blob to that container

    • Add a diagnostics message for a web role

    protected void Button1_Click(object sender, EventArgs e)
        // Setup the connection to Windows Azure Storage
        var storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("MyConnectionString"));
        var blobClient = storageAccount.CreateCloudBlobClient();
        // Get and create the container
        var blobContainer = blobClient.GetContainerReference("quicklap");
        // upload a text blob
        var blob = blobContainer.GetBlockBlobReference(Guid.NewGuid().ToString());
        byte[] data = new byte[] { 0, 1, 2, 3, 4, 5 };
        blob.UploadFromByteArray(data, 0, data.Length);
        // log a message that can be viewed in the diagnostics tables called WADLogsTable
        System.Diagnostics.Trace.WriteLine("Added blob to Windows Azure Storage");

  5. To add a breakpoint to the line of code you just added in the Button1_Click event handler, open the shortcut menu for the line of code blob.UploadFromByteArray(data, 0, data.Length); and then choose Breakpoint, Insert Breakpoint (Keyboard: F9).

  6. Add code to set up the diagnostics monitor to transfer the logs every second and start the monitor. The diagnostics monitor uses a connection string that is added when you create the Windows Azure project. The following code must be added at the beginning of the OnStart method in WebRole.cs:

                //Get the configuration object
                DiagnosticMonitorConfiguration diagObj = DiagnosticMonitor.GetDefaultInitialConfiguration();
                //Set the service to transfer logs every second to the storage account
                diagObj.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
                //Start Diagnostics Monitor with the new storage account configuration
                DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagObj);

As part of the role templates, a Windows Azure trace listener is added to the web.config. The trace listener will route trace and debug messages to the Windows Azure Diagnostics system.

Building and Debugging the Windows Azure Application

You can build your application and then you can run and debug this application locally using the compute and storage emulators that are provided as part of the Windows Azure tools. This allows you to develop your application locally before you publish it to Windows Azure. You can view the data that you add to storage and any diagnostics messages using the emulators.

To Build Your Windows Azure Application

  1. To build the project, open the shortcut menu for the Windows Azure project and then choose Build.

  2. To see the build output, open the shortcut menu for the Windows Azure project and then choose Open Folder in File Explorer. Go to the bin\Debug directory to view the build output.


To Modify Settings for Each Role

  1. To modify settings, choose a role under the Roles node for your Windows Azure project in Solution Explorer, open the shortcut menu for the role and choose Properties.

    This will display the property pages for the web role. Every role-level element and attribute in the service definition and service configuration files can be edited using the property pages.

    Visual Studio Azure Project Settings page
    If you want to run your Windows Azure application locally to debug it and you also want to publish your application to Windows Azure, this typically requires different values for the settings for your roles. For example, you might want to run four instances of a role in Windows Azure, but just one instance when you debug in your local environment. You can now have multiple service configurations in your Windows Azure project that enable you to define these different values. You can then select which one you want to use. For more information about how to do this, see Configuring an Azure Project

  2. To make changes for all the service configurations, in the Service Configuration list choose All Configurations.

  3. To change the instance count, in the Instance count text box type 2.

  4. To move to the Settings tab, choose Settings. (Keyboard: Tab to Configuration and then choose the down arrow.)

  5. To configure Visual Studio to use the local storage emulator when you run or debug your Windows Azure application, you must add the connection string that you used in the button click event handler. Use the following steps to do this:

    1. On the Settings tab choose the Add Setting button.

    2. In the Name text box, type MyConnectionString.

    3. In the Type combo box, choose Connection String.

    4. Choose the ellipsis in the Value text box. The Storage Account Connection String dialog box is displayed. If you are prompted to sign in, close the dialog box. Choose Use the Windows Azure storage emulator and then choose the OK button.

    5. On the toolbar, choose the Save icon.

  6. At the end of this walkthrough when you are ready to publish to Windows Azure, you can use this Settings tab to change the value for this connection string for the Cloud service configuration (called ServiceConfiguration.Cloud.cscfg) to use a Windows Azure storage account. You can then use this service configuration when you publish this Windows Azure cloud service.

To Debug the Windows Azure Project

  1. On the menu bar, choose Debug, Start Debugging (Keyboard: F5).

    If the Windows Azure project is not set as your startup project, the following error occurs when you click the button to trigger the breakpoint: External component has thrown an exception. The reason that the error occurs is because the development fabric must be initialized in order to invoke the Windows Azure API calls. To set the Windows Azure project as the startup project, open the shortcut menu for your Windows Azure project and choose Set as Startup Project.

    The storage emulator and the compute emulator for Visual Studio are started. These emulators enable you to run and debug your Windows Azure application locally before you publish it to Windows Azure.

    A Windows Azure icon is displayed in the notification area that enables you to view the compute emulator UI and the storage emulator UI, or to shut down these services.

    There are two versions of the compute emulator, Full and Express. In some cases when you are using one the emulators, an error message might be displayed: "Unable to determine the emulator running mode. Please ensure you have sufficient permissions." If you see this error, it is an indication that the emulator is running with a different set of permissions than you are currently using in Visual Studio. This could happen, for example, if you restart Visual Studio with a different set of permissions but don't stop the emulator. To work around this issue, simply restart the compute emulator. You can stop and start the emulator by using the shortcut menu for the Windows Azure icon in the task bar.

  2. If you are using the storage emulator for the first time, the Development Storage Initialization dialog box is displayed. When the initialization process is complete, choose the OK button to close the dialog box.

    The browser starts automatically and points to the ASP.NET web site.

    New ASP.NET web page in browser.
  3. To manage your local deployments, open the shortcut menu for the Windows Azure icon in the notification area and then choose Show Compute Emulator UI.

    The Windows Azure Compute Emulator is displayed.

  4. Choose MyWebRole to display the instances of the web role, as shown in the following illustration. Choose a specific instance to view only that individual instance.

    There are two instances of the web role because the instance count was set to 2 for the role. Either instance can process a request.

    Azure Compute Emulator runing 2 Web Roles
  5. To trigger the breakpoint that you set in the debugger, choose the button that you created.

  6. To step through the lines of code until you have uploaded the data to the blob and logged the message to the diagnostics table, press F10 three times.

  7. To view the data that you added to the blob, on the menu bar choose View, Server Explorer. Open the Windows Azure node in the tree, and then choose the Storage, Development, Blobs node. If you are prompted to sign in, close the dialog box. Double-click the quicklap node, as displayed in the following illustration:


    The data in the blob is displayed in the quicklab tab.

  8. To view the data, double-click an entry displayed in the list.

  9. To view the diagnostics messages that you logged, on the menu bar choose View, Server Explorer if it is not already visible. Open the Windows Azure node in the tree, and then choose the Storage, Development, Tables node. Double-click the WADLogsTable node.

    The diagnostics messages are displayed in the WADLogsTable tab. The data for the message is the last column in the table.

  10. To view the activity log for Windows Azure, on the menu bar choose View, Other Windows, Windows Azure Activity Log. The activity log allows you to track the status of long-running operations. You will see an entry corresponding to the text blob you downloaded.

  11. If you are using the storage emulator, open the shortcut menu for the Windows Azure icon in the notification area and then choose Show Storage Emulator UI to bring up the following dialog, which will allow you to control the running storage services as well as reset all data.

    Visual Studio Tools Emulator UI

Publish a Windows Azure Application

With the Windows Azure Tools for Microsoft Visual Studio, you can publish your Windows Azure application to Windows Azure directly from Visual Studio.

Before you can publish a Windows Azure application, you must have a Microsoft account and a Windows Azure subscription. In addition, you must set up a cloud service and storage account in the Windows Azure Management Portal that will be used by your application. For more information about how to set up these services, see Setting Up Services Required to Publish a Cloud Service from Visual Studio.

When you publish, you can select the deployment environment for your cloud service. You must also select a storage account that is used to store the application package for deployment. After deployment, the application package is removed from the storage account.

You can connect to your Windows Azure subscription from Server Explorer to simplify the process of publishing to Windows Azure. In versions of the Windows Azure SDK prior to 2.2, it was necessary to download a subscription file (.publishsettings file) and reference it when publishing a cloud service, or connecting to storage accounts or other resources. If you are using subscription files, you can still use them in Windows Azure SDK 2.2, but if you connect to Windows Azure using the steps in the next procedure, you no longer have to manage subscription files.

To connect to Windows Azure from Visual Studio

  1. In Server Explorer, choose the Windows Azure node, open its shortcut menu, and choose Connect to Windows Azure.

    Connect to Windows Azure
  2. Provide your credentials for your Windows Azure subscription. These are the same credentials you use to sign into the Management Portal. To minimize the number of times you have to provide your password, select the checkbox for Keep me signed in.

    When you close the IDE, Visual Studio saves your connection and you will still be signed in when you start Visual Studio again.

  3. (Optional) When you want to sign out, open the shortcut menu for the Windows Azure node in Server Explorer, and choose Manage Subscriptions. The Manage Windows Azure Subscriptions dialog box appears. To sign out, choose the Sign Out button, and then choose the Close button. It's not necessary to sign out unless you have another subscription you want to sign in with.

To publish a Windows Azure Application from Visual Studio

  1. Follow these steps if you have to change any connection strings in your application to use Windows Azure storage services:

    1. In Solution Explorer, open the shortcut menu for the web role in your Windows Azure project that accesses the storage services and choose Properties.

    2. In the property pages for the role, choose the Settings tab.

    3. To modify the service configuration settings only for the Cloud configuration, in the Service Configuration list choose Cloud. You can then use this service configuration when you publish your Windows Azure application.

    4. To modify any connection string settings, choose the button next to the setting.

      If you haven't yet provided credentials for Windows Azure, the sign-in page appears. Provide your credentials.

      The Create Storage Connection String dialog box appears.

    5. Under Connect using, choose the Your subscription option.

    6. In the Subscription list, choose your subscription. If the list doesn't contain the subscription that you want, choose the Download Publish Settings link.

    7. In the Account name list, choose your storage account name.

      Windows Azure Tools obtains storage account credentials automatically when you connect to Windows Azure, or by using a subscription file (.publishsettings file). To specify your storage account settings manually, get your storage account name and primary key from the Management Portal, and then choose Manually entered credentials.

    8. You must choose one of the following options to determine how the service will access the storage account:

      • Use HTTP. This is the standard option. For example, http://<account name>.blob.core.windows.net.

      • Use HTTPS for a secure connection. For example, https://<accountname>.blob.core.windows.net.

      • Specify custom endpoints for each of the three services. You can then type these endpoints into the field for the specific service.

        If you create custom endpoints this allows you to create a more complex connection string. When you use this string format, you can specify storage service endpoints that include a custom domain name that you have registered for your storage account with the Blob service. In addition, you can grant access only to blob resources in a single container through a shared access signature. For more information about how to create custom endpoints, see How to Configure Connection Strings.

    9. To save these connection string changes, choose the OK button.

      After you save these changes, you can build and run your Windows Azure application from within Visual Studio using this service configuration that you updated and verify that it works as expected against the Windows Azure storage services. For more information about how to select a service configuration to run and debug locally, see How to: Configure a Azure Project with Visual Studio.

  2. To publish your application, open the shortcut menu for the Windows Azure Project that contains your role in Solution Explorer. Then choose Publish, as shown in the following illustration:


    The Publish Windows Azure Application dialog box appears.

  3. If you haven't signed in, choose the Sign In button, provide your Windows Azure user name and password.

    This is one of the publishing wizard screens
  4. In the Choose your subscription list, choose the subscription to use for this deployment.

    If you choose <Manage…>, you can create, edit, or delete subscriptions.

  5. When you're satisfied with your subscription information, choose the Next button to open the Settings page, and then choose the Common Settings tab.

    Publishing Wizard Common Settings
  6. In the Environment list, choose Production. This is the deployment environment that's used to host your cloud service. By default, these include Staging and Production.

    You can deploy to an environment that's empty or that another deployment is using.

  7. In the Build configurationlist, choose the configuration you want, such as Release.

  8. In the Service configuration list, choose Cloud.

  9. To configure remote desktop connections for this deployment environment so that you can connect to the virtual machine that's running each instance of a role, select the Enable Remote Desktop for all roles checkbox, create account credentials to use when you log on to the virtual machines..

    For more information, see Using Remote Desktop with Azure Roles.

  10. Choose the Advanced Settings tab.

    Publish Wizard Advanced Settings
  11. On the Storage account list, choose the account to use to upload the service package to this account as part of the deployment process.

    This storage account doesn't have to be the storage account that you plan to use for the data for your application.

  12. If you don't want to automatically overwrite an existing deployment when you publish a new build of your application, select the Deployment update check box.

    For more information about deployment update settings, see Publish Windows Azure Application Wizard.

  13. A default name is created for your deployment. To change this name, you can enter a new name or amend the default name in Deployment label. This name is used in the Management Portal.

  14. To append the date and time to the label for the deployment, select the Append current date and time check box.

  15. To enable IntelliTrace for this deployment, select the Enable IntelliTrace check box.

    IntelliTrace provides debugging information for your application that you can use to step through your code from Visual Studio Ultimate. For more information, see Debugging Using IntelliTrace.

    You can enable IntelliTrace only when you publish your application from Visual Studio Ultimate.

  16. To enable profiling for this deployment to determine the performance of your Windows Azure application, select the Enable profiling check box. Profiling provides performance information for your application. For more information about how to configure the settings for profiling, see Testing the Performance of a Cloud Service.

    You can enable either IntelliTrace or profiling when you publish your Windows Azure application. You cannot enable both.

  17. (Optional) If you are publishing from Visual Studio and you have installed the latest version of the Windows Azure tools, you can also enable Web Deploy for all your web roles. For the requirements and the detailed steps to do this, see To Enable Web Deploy When You Publish Your Application.

  18. Choose the Next button to review your settings.

    Publish Wizard summary page
  19. To publish your Windows Azure application, choose the Publish button. Visual Studio starts the deployment process. You can see the progress of the deployment from the Windows Azure Activity Log window. This log is automatically displayed when the deployment process starts. You can expand the line item in the activity log to show detailed information, as shown in the following illustration:

  20. (Optional) To cancel the deployment process, open the shortcut menu for the line item in the activity log and choose Cancel and remove. This stops the deployment process and deletes the deployment environment from Windows Azure.

    To remove this deployment environment after it has been deployed, you must use the Management Portal.

  21. (Optional) After your role instances have started, Visual Studio automatically shows the deployment environment node in Server Explorer. From here you can see the status of the individual role instances. For more information about how to use Server Explorer to view your deployments, see Viewing the State of a Cloud Service using Server Explorer.

    The following illustration shows the role instances while one of the instances is still in the Busy state, becaue it is still being initialized:

  22. To access your application after deployment, choose the arrow next to your deployment when a status of Completed is displayed in the Windows Azure Activity log. To start a browser with your application, choose the hyperlink that is displayed in the deployment details.

Next Steps

See Also

Community Additions

© 2014 Microsoft