Special connect() issue 2014

Volume 29 Number 12A

Azure SDK 2.5 : Azure SDK 2.5 for .NET and Visual Studio 2015 Overview

Mohit Srivastava; issue 2014

The Azure SDK for .NET makes it easy for your .NET-based cloud application to consume Microsoft Azure resources. Moreover, Visual Studio is integrated into the cloud development experience. You can view and manage cloud resources directly from Visual Studio, add cloud services to your projects, and publish to the cloud from the IDE.

This article gives a quick tour of some of the new features in Azure SDK 2.5 for .NET. Many of the features shown here support Visual Studio 2012 and Visual Studio 2013, but some require Visual Studio 2015 Preview, where noted.

The flow of this article is intended to follow a typical development workflow, while focusing on the new features of Azure SDK 2.5:

  • Sign in to Visual Studio and Azure
  • Create a cloud project
  • Add cloud services and features, such as Azure Storage, WebJobs, and single sign-on
  • Enable diagnostics and code analysis

Sign in to Visual Studio and Azure

When you launch Visual Studio, you’re prompted to sign in with a Microsoft account. In Visual Studio 2015 Preview, if the account is also associated with your Azure Subscription, you’re automatically signed in to Azure. To view your Azure resources, select Server Explorer from the View menu.

Visual Studio 2015 Preview lets you sign in with multiple accounts at once. For example, you might have a Microsoft account associated with an MSDN subscription, and also sign in with your organization account for your company. Server Explorer shows the resources for all of your accounts.

To add another account, right-click on the Azure node in Server Explorer and choose Manage Subscriptions. This brings up a dialog that shows the accounts you’ve added to Visual Studio. To add a new account, click Add an account. In the Manage Subscriptions dialog, you can also filter which Azure resources appear in Server Explorer by unchecking accounts, subscriptions, regions or certificates.

Another nice improvement is that you can now view your SQL Databases in Server Explorer without importing a certificate. Simply sign in to your Azure account and view your SQL Databases in Server Explorer. (This feature is also available in Visual Studio 2013 Update 4.)

QuickStart Templates

To get started with Azure quickly, you can use the new QuickStart templates. These templates provide sample code, showing how to use the Azure SDK and other libraries to interact with Azure Services. Find the QuickStart templates under File | New | Project | C# | Cloud | QuickStarts.

In the current release, there are QuickStart templates for Azure Storage (Blobs, Tables, Queues), DocumentDB, Azure Redis Cache Service, Azure Media Services, Azure WebJobs and Service Bus (Topics and Queues). There are also QuickStarts that show how to use the Microsoft Azure Management Libraries (MAML) to programmatically manage Azure resources.

Creating Resource Groups and Cloud Deployment Projects

A typical cloud app might use several different Azure resources. For example, an app might be hosted in an Azure Website, use a SQL Database for relational data, use Azure Storage for blobs or queues, and use Azure Redis Cache for low-latency data access.

Resource groups are a way to manage all of your resources as a logical group. With Azure SDK 2.5, you can create and deploy a set of resources in a resource group, using the new Cloud Deployment Project template. Currently, there are templates for:

  • Azure Website
  • Azure Website + SQL
  • Azure Website + SQL + Redis Cache

In future releases, more templates will be added for application scenarios that use other Azure features such as networking, storage and virtual machines. Select the template closest to the solution you’re building.

Here’s how it works. In Visual Studio, select File | New | Project | Cloud | Cloud Deployment Project. Name the project MyAzureCloudApp and click OK. Then select from the list of common Azure Gallery templates, as shown in Figure 1.

Azure Galley Templates
Figure 1 Azure Galley Templates

For example, select the Azure Website template and name the project MyAzureCloudApp. After you select the template, you’re prompted for an ASP.NET project type (Web Forms, MVC, Web API and so on). Visual Studio creates a solution with two projects:

  • MyAzureCloudApp is the ASP.NET application.
  • MyAzureCloudApp.Deployment is the deployment project.

The deployment project, shown in Figure 2, includes the following files:

  • WebSiteDeploy.json: A deployment template.
  • WebSiteDeploy.param.dev.json: Template parameters.
  • Publish-AzureResourceGroup.ps1: A Windows PowerShell script that can be used to deploy your resources to Azure.

Deployment Project Files
Figure 2 Deployment Project Files

Together, the deployment template (WebSiteDeploy.json) and the parameters file (WebSiteDeploy.param.dev.json) specify the details for deploying and provisioning resources.

From Visual Studio, it’s easy to deploy your resources to Azure. In Solution Explorer, right-click the deployment project, and select Deploy | New Deployment. In the New Deployment dialog, select Resource Group. This brings up the Deploy to Resource Group dialog.

To create a new resource group, click on the Resource group combo box and select Create New. Name the resource group, select a region, and click Create. Clicking the Create button provisions your Azure Resource Group, but does not spin up any Azure resources yet. (That will happen when you deploy.)

Next, click Edit Parameters to edit the parameters for the deployment template, such as Web site name, Web hosting plan and Web site location. If any required values are missing, they’re shown with a red warning icon. When you click Save, the parameter values are saved back to the WebSite­Deploy.param.dev.json file. The next time you deploy, you don’t need to reenter this information. Being able to customize and store the local JSON reduces the chance of errors when redeploying the resources.

Once all the parameters have been specified, click Deploy to provision resources and deploy the application. You can see detailed progress in the Output window in Visual Studio. You can also view the resource group and the deployed resources in the new Azure Management Portal.

The deployment template and parameter files make it easy to work in a cloud lifecycle pattern and treat configuration as code. For example, you could create several parameter files, such as *.test.json and *.staging.json, so that a single template can deploy to multiple environments for testing, staging and so on. Visual Studio has a built-in JSON editor, and includes IntelliSense based on the published JSON schemas, which makes it easy to edit the JSON files.

Enterprise Single Sign-On

A common task for business applications is to configure the application for enterprise single sign-on (SSO) using Azure Active Directory. In Visual Studio 2015, you can do this easily at any point during development. Right-click the project in Solution Explorer and select Configure Azure AD Authentication.

This will bring up a wizard to guide you through the process of configuring your application to work with Active Directory. Specifying an Active Directory Domain in the wizard will register your application with that Active Directory and configure your application to prompt for sign-in. Registering your application in a domain is a great way to get started in a dev-test environment. You can easily reconfigure the application’s config files to use other domains as you move from one environment to the next in the application’s lifecycle. You can find out more about this feature in the Azure Active Directory Overview video at bit.ly/1xCRpoc.

Add Connected Services

Once you’ve created a cloud application, Visual Studio 2015 makes it easy to incorporate additional cloud services into your app, including Azure Storage, Azure Mobile Services, Office 365 or Salesforce.

Here’s how you connect the ASP.NET application to an Azure Storage account. In Solution Explorer, expand the Web application project. Next, right-click the References node and select Add Connected Service. Select Azure Storage from the list of services and click Configure.

Visual Studio shows a list of your existing storage accounts. Choose one of these, or provision a new one. Then click Add to connect to that storage account from your application. This adds Azure Storage references using the latest NuGet packages, and adds a connection string for your selected storage account in web.config. Visual Studio also shows a Getting Started page to help you get started with Azure Storage. To revisit the Getting Started page, right-click the GettingStarted.html file in Solution Explorer and choose View in Browser.

Blob Folders in Storage Explorer

Blob storage is persistent file storage for the cloud. A blob can be any type of text or binary data, such as a document, media file or application installer. Blob folders are a way to group blobs into logical units. This is particularly useful if you’re using one blob container to store all your information. In terms of implementation, a blob folder is really just a prefix for the blob name, delimited with the / character. For example, if you have a blob named file.png inside a folder named pictures, the URL for that blob will be in the following format: 


Starting with this release, you can create blob folders from inside Visual Studio, and navigate through the contents of blob folders.

In Server Explorer, expand the Storage node. Under this node are your storage accounts. Expand [storage account] | Blobs | [container name]. Right-click the container name and select View Blob Container. You can also create new containers from Server Explorer.

Navigate through folders by double-clicking on a folder to go inside it, and using the up arrow to go up a level. You can create a new folder when you upload a blob to Azure Storage using the upload button.


Azure WebJobs provide an easy way to run scripts or programs as background processes on Azure Websites. You can upload and run executable files such as .cmd, .bat, .exe (.NET), .ps1, .sh, .php, .py, .js and .jar. These programs run as WebJobs on a schedule (cron) or continuously. Azure WebJobs and the WebJobs SDK are now Generally Available. To learn more about WebJobs, see aka.ms/webjobs.

You can also add a WebJob project to an existing Web application. In Solution Explorer, right-click the Web application project and click Add | New Azure WebJob Project. As Figure 3 shows, you can select whether you want the WebJob to run continuously, on a fixed schedule or on demand. For scheduled WebJobs, select the start and end times and the frequency.

Adding an Azure WebJob to a Project
Figure 3 Adding an Azure WebJob to a Project

The Program.cs file for an on-demand or scheduled job contains the following code for executing the WebJob explicitly:

static void Main()
  var host = new JobHost();
    new { value = 20 });

Continuous WebJobs get a different Program.cs file, which includes a call to start the WebJob host and block it from exiting:

static void Main()
  var host = new JobHost();
  // The following code ensures the WebJob will be running continuously

For more information about creating and deploying WebJob projects, see bit.ly/1pGVplo.

With Azure SDK 2.5, your WebJobs now appear in Server Explorer. They’re listed under the Azure Website where they’re deployed, and are grouped by run mode (Continuously, On Demand or Schedule). By right-clicking a WebJob in Server Explorer, you can open the dashboard for that WebJob. You can also run an on-demand job, or stop and start continuous jobs.

Continuous WebJobs now support remote debugging. Once a continuous WebJob has started, you can attach the Visual Studio debugger to the WebJob running in the cloud. To attach the debugger, right-click the WebJob in Server Explorer and select Attach Debugger. By placing a breakpoint and attaching the debugger, you can be stepped through your code just as if it were running locally in Visual Studio.


The SDK includes new tools in Server Explorer that make you more productive working with your Big Data using HDInsight hosted Hadoop services and using Hive to query your datasets.

Like any other Azure service, you can browse the HDInsight resources in your subscription and do common dev-test tasks. You can use the Server Explorer to browse your Hive tables, examine schemas and even query the first 100 rows of a table. This helps you understand the shape of the data with which you’re working.

Also, there’s tooling to create Hive queries and submit them as jobs. Use the context menu against a Hadoop cluster to immediately begin with “Write a Hive Query” for quick scripts. The Job Browser tool helps you visualize the job submissions and status. Double-click on any job to get a summary and details in the Hive Job Summary window. In the example in Figure 4, the table is queried with geographic info to find the count of all countries and then sort by country.

Viewing Hive Jobs in Visual Studio Server Explorer
Figure 4 Viewing Hive Jobs in Visual Studio Server Explorer

The backing blob storage used by HDInsight is listed in Server Explorer. You can navigate to any blob container and open it to work with files. The backing store is associated with the Hadoop cluster during cluster creation in the Azure dashboard. Management of the Hadoop cluster is still performed in the same Azure dashboard.

For more complex script development and lifecycle management, you can create Hive projects within Visual Studio. The New Project dialog now has an HDInsight Template category. A helpful starting point is the Hive Sample project type. This project is pre-populated with a more complex Hive query and sample data for the case of processing Web server logs.

Improved Diagnostics Logging for Cloud Services and Virtual Machines

Azure SDK 2.5 includes improvements for diagnostics logging in both Azure Cloud Services Platform as a Service (PaaS) and Virtual Machines Infrastructure as a Service (IaaS).

For example, you can now perform structured and semantic logging using Event Tracing for Windows (ETW) event sources. ETW event sources and event IDs allow you to define logical events and stages of the application workflow. Then you can track events across multiple tiers, to help diagnose issues in your application workflow. You can also collect crash dumps. By default, the most common processes for cloud roles are pre-selected for crash dump collection. One very nice feature is that you can update the diagnostic configuration for a running service, after the cloud service is published.

Microsoft Code Analysis for Azure Preview

What if you could find problems in your code as you type? Not just compilation errors, but subtler coding issues.

The .NET Compiler Platform in Visual Studio 2015 Preview provides new code analysis capabilities that detect code issues in real time as you write your code. Leveraging these capabilities, the Azure team has put together a small set of code analysis rules for Azure. These rules identify issues in your code and, when possible, recommend automatic fixes. They’re available through the Microsoft Code Analysis for Azure NuGet package.

To install the package, right-click your solution and choose Manage NuGet Packages for Solution. Make sure the Include Prerelease checkbox is checked and search for Azure Code Analysis.

This should find the Microsoft.VisualStudio.Azure.CodeAnalysis package. Select projects in your solution and click Install to enable code analysis for those projects. Once an analyzer is added to the project, code analysis is always running. To run code analysis on the entire solution, build the solution. Any code analysis warnings or errors will automatically show up in the error list as you make edits to a source file.

As you code, any line that has an issue will display a red underline for errors or a green underline for warnings. Hover over the underlined code to get more information. Click on the light bulb next to the issue to get additional details on fixes. For example, Figure 5 shows a code issue with the Run method of a worker role being declared as async. This is a common scenario where you might want to perform some asynchronous operations in a worker role. However, declaring the Run method itself as async will cause the role to restart in an infinite loop. The code analysis detects the issue and offers an automatic fix, which refactors the Run method and moves the async operations to another method.

Code Analysis with a Suggested Code Fix
Figure 5 Code Analysis with a Suggested Code Fix

Not all code issues have automatic fixes. If no automatic fix can be provided, the light bulb menu will point you to documentation describing how to fix the issue.

The code analysis rules provided in the NuGet package are just an initial set of rules designed to showcase the code analysis capabilities in the new .NET compiler. As the team receives feedback, we will provide more rules and continue to iterate on the experience. 

Wrapping Up

Figure 6 shows a summary of the new features in Azure SDK 2.5 for .NET. Azure SDK 2.5 and Visual Studio 2015 Preview make it easier than ever to get started developing rich cloud applications.

Figure 6 Summary of New Features in Azure SDK 2.5 for .NET Framework

Feature Visual Studio 2015 Preview Visual Studio 2013/2012
Connect Visual Studio to Multiple Azure Accounts x  
QuickStart Templates x x
Cloud Deployment Projects x x (Visual Studio 2013 only)
Add Connected Service Dialog x  
Blob folders in Storage Explorer x x
WebJobs: Server Explorer Support and Remote Debugging x x
HDInsight: Server Explorer and Hive Query Support x x
Configure Enterprise Single Sign-On (SSO) x  
Diagnostics Improvements x x
Code Analysis for Azure (Preview) x  

If you don’t already have an Azure account, you can sign up for a free trial and start using all of the features discussed here. There are two ways to get started with the SDK:

  • Install the SDK locally: Download from the Azure .NET Developer Center (bit.ly/1uR4Z5h)
  • VM Image in Azure: The fastest way to get started with Azure SDK 2.5 is by using a VM from the Azure Virtual Machine gallery. You can create a VM that has Azure SDK 2.5 installed, with either a Visual Studio 2015 Preview or Visual Studio Community 2013 image. Both of these images are available to all Azure customers. If you’re an MSDN subscriber, you can take advantage of additional Visual Studio 2013 images based on Windows 8.1 and Windows Server 2012, which have been updated to Visual Studio 2013 Update 4 and Azure SDK 2.5.

You can then visit the Azure .NET Developer Center (bit.ly/1uR4Z5h) to learn more about how to build apps with it.

Saurabh Bhatia is a program manager at Microsoft working on Visual Studio Azure Tools. Before this, Bhatia worked on developer tools for Office 365 APIs and apps for Office and SharePoint. You can reach him at saurabh@microsoft.com.

Mohit Srivastava is a lead program manager at Microsoft responsible for Azure and Web Developer Tools and Services. In prior roles, he worked “lower in the stack” on core Azure and Windows services and “higher in the stack” as cofounder at a microblogging startup. You can reach him at mohisri@microsoft.com

Thanks to the following Microsoft technical experts for reviewing this article: Brady Gaster and Michael Wasson
Brady Gaster is a Program Manager on the Azure SDK and Visual Studio Web Tools Extensions teams. Brady’s teams develop client libraries and command line experiences that make it easier for developers to party in the cloud from the command line, managed code, and within Visual Studio. He dabbles in Scala and other alternative JVM languages, tinkers with the .NET Micro Framework building small robots and hardware prototypes, and pretends to be a musician. You can reach Brady via email at bradyg@microsoft.com or via Twitter at @bradygaster.

Mike Wasson is a programmer-writer at Microsoft. For many years he documented the Win32 multimedia APIs. He currently writes about ASP.NET and Microsoft Azure. You can reach him at mwasson@microsoft.com.