'Dev Tunnels' In Visual Studio 2022 For Azure Functions

On November 15th has been announced the public preview of 'Dev Tunnel'. You can find the announcement in this post, where Sayed Ibrahim explains how our ASP.NET project can be port tunneling (forwarding) to enable connections between machines that cannot directly connect to each other.

In the past, we have accomplished this kind of requirement with tools like ngrok. But with the introduction of this feature in Visual Studio, we can do it now natively in Visual Studio without the necessity to download and execute separately any external tool.

In the announcement, the focus is on ASP.NET, but if we continue reading to the end, we'll notice that the feature is also now available for Azure Functions. In this article, we'll learn about the minor differences but important to understand on trying to execute/debug our projects.

In Azure Function we could find that we can implement REST APIs with Http Trigger and sometimes we need to expose this endpoint for the internet and be able to debug our code. In this documentation from Twilio, in the 'Test your Azure Function webhook locally' section, we can find a use case where they are using ngrok to test the webhook for responses to their messaging platform. Here is where 'Dev Tunnel' can come to the scene.

'Dev Tunnel' configuration for Azure Functions

In the announcement article, he mentioned that the feature needs to be activated. Once we had it activated for Visual Studio, we learned that the feature is activated for our project editing the launchSettings.json. But for Azure Function the structure is a little different. And here you can find how it should be:

  "profiles": {
    "ProjectName": {
      "commandName": "Project",
      "commandLineArgs": "--port 7173",
      "launchBrowser": false,
      "devTunnelEnabled": true,
      "devTunnelAccess": "public"

And when we debug/execute the project will find that the exposed endpoint continues to show localhost for the URL.

Dev Tunnel configuration for Azure Functions

It is the Output Window under the 'Dev Tunnels' output where we can find the taken URL for the execution.

Dev Tunnel configuration for Azure Functions

And then, when we try to access the URL we'll see the warning message

Dev Tunnel configuration for Azure Functions

and once we click Continue button, the result can be seen

Dev Tunnel configuration for Azure Functions

Similar Articles