Quickstart: Debug and iterate with Visual Studio and .NET Core on Kubernetes with Azure Dev Spaces

In this guide, you will learn how to:

  • Set up Azure Dev Spaces with a managed Kubernetes cluster in Azure.
  • Iteratively develop code in containers using Visual Studio.
  • Debug code running in your cluster using Visual Studio.

Azure Dev Spaces also allows you debug and iterate using:


  • An Azure subscription. If you don't have one, you can create a free account.
  • Visual Studio 2019 on Windows with the Azure Development workload installed. You can also use Visual Studio 2017 on Windows with the Web Development workload and Visual Studio Tools for Kubernetes installed. If you don't have Visual Studio installed, download it here.

Create an Azure Kubernetes Service cluster

You must create an AKS cluster in a supported region. To create a cluster:

  1. Sign in to the Azure portal

  2. Select + Create a resource > Kubernetes Service.

  3. Enter the Subscription, Resource Group, Kubernetes cluster name, Region, Kubernetes version, and DNS name prefix.

    Create AKS in the Azure portal

  4. Click Review + create.

  5. Click Create.

Enable Azure Dev Spaces on your AKS cluster

Navigate to your AKS cluster in the Azure portal and click Dev Spaces. Change Enable Dev Spaces to Yes and click Save.

Enable Dev Spaces in the Azure portal

Create a new ASP.NET web app

  1. Open Visual Studio.
  2. Create a new project.
  3. Choose ASP.NET Core Web Application and name your project webfrontend.
  4. Click OK.
  5. When prompted, choose Web Application (Model-View-Controller) for the template.
  6. Select .NET Core and ASP.NET Core 2.0 at the top.
  7. Click OK.

Connect your project to your dev space

In your project, select Azure Dev Spaces from the launch settings dropdown as shown below.

In the Azure Dev Spaces dialog, select your Subscription and Azure Kubernetes Cluster. Leave Space set to default and enable the Publicly Accessible checkbox. Click OK.

This process deploys your service to the default dev space with a publicly accessible URL. If you choose a cluster that hasn't been configured to work with Azure Dev Spaces, you'll see a message asking if you want to configure it. Click OK.

The public URL for the service running in the default dev space is displayed in the Output window:

Starting warmup for project 'webfrontend'.
Waiting for namespace to be provisioned.
Using dev space 'default' with target 'MyAKS'
Successfully built 1234567890ab
Successfully tagged webfrontend:devspaces-11122233344455566
Built container image in 39s
Waiting for container...

Service 'webfrontend' port 'http' is available at http://webfrontend.1234567890abcdef1234.eus.azds.io/
Service 'webfrontend' port 80 (http) is available at http://localhost:62266
Completed warmup for project 'webfrontend' in 125 seconds.

In the above example, the public URL is http://webfrontend.1234567890abcdef1234.eus.azds.io/. Navigate to your service's public URL and interact with the service running in your dev space.

This process may have disabled public access to your service. To enable public access, you can update the ingress value in the values.yaml.

Update code

If Visual Studio is still connected to your dev space, click the stop button. Change line 20 in Controllers/HomeController.cs to:

ViewData["Message"] = "Your application description page in Azure.";

Save your changes and start your service using Azure Dev Spaces from the launch settings dropdown. Open the public URL of your service in a browser and click About. Observe that your updated message appears.

Instead of rebuilding and redeploying a new container image each time code edits are made, Azure Dev Spaces incrementally recompiles code within the existing container to provide a faster edit/debug loop.

Setting and using breakpoints for debugging

If Visual Studio is still connected to your dev space, click the stop button. Open Controllers/HomeController.cs and click somewhere on line 20 to put your cursor there. To set a breakpoint hit F9 or click Debug then Toggle Breakpoint. To start your service in debugging mode in your dev space, hit F5 or click Debug then Start Debugging.

Open your service in a browser and notice no message is displayed. Return to Visual Studio and observe line 20 is highlighted. The breakpoint you set has paused the service at line 20. To resume the service, hit F5 or click Debug then Continue. Return to your browser and notice the message is now displayed.

While running your service in Kubernetes with a debugger attached, you have full access to debug information such as the call stack, local variables, and exception information.

Remove the breakpoint by putting your cursor on line 20 in Controllers/HomeController.cs and hitting F9.

Clean up your Azure resources

Navigate to your resource group in the Azure portal and click Delete resource group. Alternatively, you can use the az aks delete command:

az group delete --name MyResourceGroup --yes --no-wait

Next steps