Do you use port forwarding to test local builds?

Last updated by Alex Rothwell [SSW] 10 months ago.See history

In the old days, you had to deploy your entire application to a staging environment just so you could share it with other members of your team. That process was a huge hassle and made it much harder to get feedback quickly.

Luckily, port forwarding is the silver...errr...golden bullet that solves this issue. Port forwarding helps by exposing a locally running application over the internet for testing or other purposes.

3rd party solutions have existed for awhile, but they need configuration and cost money. Now, Dev Tunnels is a new port forwarding feature in Visual Studio that can help developers do that for free.

Video: Simplify Remote Testing with Dev Tunnels | Daniel Mackay | SSW Rules (7 min)

Use Cases

  • Feedback on a locally running application
  • Testing of an application on a mobile phone or tablet
  • Webhooks: public service needing to make an API call to your local website (e.g. Twilio or Sendgrid webhook)
  • Azure SignalR: Get the Azure hosted signal R service to send websocket messages to your local website
  • Azure APIM: Use APIM as a gateway that points to a locally running API
  • Power Platform: Debug Power Platform by running your API locally
  • Locally testing applications which need to communicate on a port blocked from your environment (i.e. using a Jump Server)

Options

Dev Tunnels Setup

Dev Tunnels is currently only available via Visual Studio 2022 17.5+

Pre-Requisites

  • Visual Studio 2022 17.5+
  • ASP.NET Core project

Usage

  1. Enable the Dev Tunnels via Tools | Options | Environment | Preview Features:

    screen1
    Figure: Enabling Dev Tunnels

  2. Open the Dev Tunnels window via View | Other Windows | Dev Tunnels
  3. Create and configure a new Dev Tunnel:

    screen2
    Figure: Configuring a Dev Tunnel

  4. Run the website
  5. Get the public URL via Dev Tunnels | Tunnel URL:

    screen4
    Figure: Finding the Dev Tunnel URL

  6. Confirm you can browse your site via the public URL:

    screen3
    Figure: Testing the Dev Tunnel on desktop

  7. Confirm you can browse via a mobile:

    screen5
    Figure: Testing the Dev Tunnel on mobile

Best Practices on Access Types

  • Private: Ideal if you are testing yourself on mobile device
  • Organization (Recommended): Ideal if you need feedback from others within the organization
  • Public: For when the other two options are not possible (e.g. Web hooks). In this case it is recommend to use Temporary tunnels so that the URL is no longer available once you've closed visual studio

Resources

We open source. Powered by GitHub