Use dev tunnels in Visual Studio to debug your web APIs

To quickly debug and test your web APIs within Microsoft Power Automate or Power Apps, you can use dev tunnels in Visual Studio. Dev tunnels enables ad-hoc connections between machines that can't directly connect to each other. Once this feature is enabled, you'll see that debugging (F5) automatically creates a dev tunnel URL that you can use to connect to Power Apps or Power Automate.

Prerequisites

Step 1: Configure your ASP.NET Core project in Visual Studio

When you're developing ASP.NET Core APIs in Visual Studio, the launch settings are stored in the file Properties/launchSettings.json. This file contains one or more launch profiles.

To enable dev tunnels, add the property "devTunnelEnabled": true in the launch profile.

Tunnels are created with private access by default, meaning that only the user who created the tunnel can access it after signing in. You can control this access by adding the devTunnelAccess property. Valid values include the following:

  • private: Only the user who created the tunnel can access it after signing in.
  • org: Only users in the organization can access it after signing in.
  • public: The tunnel is accessible by anyone and no sign-in is needed.

In the following example, the tunnel is set to public to simplify the example.

{
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:4921",
      "sslPort": 44305
    }
  },
  "profiles": {
    "PortTunnelingAPI": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "https://localhost:7018;http://localhost:5018",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "devTunnelEnabled": true,
      "devTunnelAccess":"Public"
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

After you select F5 (Debug > Start Debugging) or the Start Debugging button, you'll see the dev tunnel URL.

URL without dev tunnels:

Screenshot of the URL before debugging.

URL with dev tunnels:

Screenshot of the URL after debugging.

Step 2: Create a custom connector for your web API using the dev tunnel URL

A custom connector is a wrapper around a REST API and allows Power Automate or Power Apps solutions to communicate with your web API. There are many ways to create a custom connector. The following sections explain how to use the dev tunnel URL and create a custom connector from scratch, or with API Management.

Create a custom connector from scratch

  1. On the General tab, post the dev tunnel URL into the Host field.

    Screenshot of the General tab.

  2. On the Security tab, select No authentication from the dropdown menu.

    Screenshot of the Security tab.

  3. On the Definition tab, define your HTTP methods by adding actions. For the URL action, use the dev tunnel base URL + /actionName (for example, https://50tt58xr-7223.usw2.devtunnels.ms/weatherforecast).

    Screenshot of the Definition tab.

  4. On the Test tab, after adding your connection you can test your web API.

    Screenshot of the Testing tab.

    For instructions, go to Create a custom connector from scratch.

Create a custom connector with API Management

  1. Go to your Azure API Management instance in the Azure portal.

  2. Modify the runtime URL of your API in the menu under Backends and select your API instance.

  3. On the Properties tab, replace the Runtime URL with the dev tunnel URL and select Save.

    Screenshot of the Settings tab.

  4. On the Power Platform tab, you you can now create a custom connector. For instructions, go to Export APIs from Azure API Management to the Power Platform.

Step 3: Add the custom connector to Power Apps or Power Automate

To debug your web API, you'll have to use a custom connector from a Power Apps app or a Power Automate flow.

When your custom connector is integrated in your Power Platform solution, you can set a breakpoint, and debug your Power Apps app or Power Automate flow.

Note

Breakpoints are the most basic and essential feature of reliable debugging. A breakpoint indicates where Visual Studio should suspend your running code so you can take a look at the values of variables, behavior of memory, or if a branch of code is getting run.

Animation demo of debugging.

Provide feedback

We greatly appreciate feedback on issues with our connector platform, or new feature ideas. To provide feedback, go to Submit issues or get help with connectors and select your feedback type.