Skip to content
Docs Try Aspire

DevTunnelsResourceBuilderExtensions Methods

Class Methods 11 members
Provides extension methods for adding dev tunnels resources to an Hosting.IDistributedApplicationBuilder.
AddDevTunnel(IDistributedApplicationBuilder, string, string?, DevTunnelOptions?) Section titled AddDevTunnel(IDistributedApplicationBuilder, string, string?, DevTunnelOptions?) extension IResourceBuilder<DevTunnelResource>
Adds a dev tunnel resource to the application model.
public static class DevTunnelsResourceBuilderExtensions
{
public static IResourceBuilder<DevTunnelResource> AddDevTunnel(
this IDistributedApplicationBuilder builder,
string name,
string? tunnelId = null,
DevTunnelOptions? options = null)
{
// ...
}
}
builder IDistributedApplicationBuilder
name string
tunnelId string? optional
options DevTunnelOptions? optional
Dev tunnels can be used to expose local endpoints to the public internet via a secure tunnel. By default, the tunnel requires authentication, but anonymous access can be enabled via DevTunnelsResourceBuilderExtensions.WithAnonymousAccess.

The following example shows how to create a dev tunnel resource that exposes all endpoints on a web application project and enable anonymous access:

var builder = DistributedApplication.CreateBuilder(args);
var web = builder.AddProject<Projects.WebApp>("web");
var tunnel = builder.AddDevTunnel("mytunnel")
.WithReference(web)
.WithAnonymousAccess();
builder.Build().Run();
GetEndpoint(IResourceBuilder<DevTunnelResource>, IResourceBuilder<TResource>, string) Section titled GetEndpoint(IResourceBuilder<DevTunnelResource>, IResourceBuilder<TResource>, string) extension EndpointReference
Gets the tunnel endpoint reference for the specified target resource and endpoint.
public static class DevTunnelsResourceBuilderExtensions
{
public static EndpointReference GetEndpoint<TResource>(
this IResourceBuilder<DevTunnelResource> tunnelBuilder,
IResourceBuilder<TResource> resourceBuilder,
string endpointName)
{
// ...
}
}
tunnelBuilder IResourceBuilder<DevTunnelResource> The dev tunnel resource builder.
resourceBuilder IResourceBuilder<TResource> The target resource builder.
endpointName string The name of the endpoint on the target resource.
EndpointReference An ApplicationModel.EndpointReference representing the public tunnel endpoint.
InvalidOperationException Thrown when the specified endpoint is not found in the tunnel.
GetEndpoint(IResourceBuilder<DevTunnelResource>, IResource, string) Section titled GetEndpoint(IResourceBuilder<DevTunnelResource>, IResource, string) extension EndpointReference
Gets the tunnel endpoint reference for the specified target resource and endpoint.
public static class DevTunnelsResourceBuilderExtensions
{
public static EndpointReference GetEndpoint(
this IResourceBuilder<DevTunnelResource> tunnelBuilder,
IResource resource,
string endpointName)
{
// ...
}
}
tunnelBuilder IResourceBuilder<DevTunnelResource> The dev tunnel resource builder.
resource IResource The target resource.
endpointName string The name of the endpoint on the target resource.
EndpointReference An ApplicationModel.EndpointReference representing the public tunnel endpoint.
GetEndpoint(IResourceBuilder<DevTunnelResource>, EndpointReference) Section titled GetEndpoint(IResourceBuilder<DevTunnelResource>, EndpointReference) extension EndpointReference
Gets the tunnel endpoint reference for the specified target endpoint.
public static class DevTunnelsResourceBuilderExtensions
{
public static EndpointReference GetEndpoint(
this IResourceBuilder<DevTunnelResource> tunnelBuilder,
EndpointReference targetEndpointReference)
{
// ...
}
}
tunnelBuilder IResourceBuilder<DevTunnelResource> The dev tunnel resource builder.
targetEndpointReference EndpointReference The target endpoint reference.
EndpointReference An ApplicationModel.EndpointReference representing the public tunnel endpoint.
WithAnonymousAccess(IResourceBuilder<DevTunnelResource>) Section titled WithAnonymousAccess(IResourceBuilder<DevTunnelResource>) extension IResourceBuilder<DevTunnelResource>
Allows the tunnel to be publicly accessed without authentication.
public static class DevTunnelsResourceBuilderExtensions
{
public static IResourceBuilder<DevTunnelResource> WithAnonymousAccess(
this IResourceBuilder<DevTunnelResource> tunnelBuilder)
{
// ...
}
}
tunnelBuilder IResourceBuilder<DevTunnelResource> The resource builder.
IResourceBuilder<DevTunnelResource> The resource builder.
WithReference(IResourceBuilder<DevTunnelResource>, IResourceBuilder<TResource>, bool) Section titled WithReference(IResourceBuilder<DevTunnelResource>, IResourceBuilder<TResource>, bool) extension IResourceBuilder<DevTunnelResource>
Adds ports on the dev tunnel for all endpoints found on the referenced resource and sets whether anonymous access is allowed.
public static class DevTunnelsResourceBuilderExtensions
{
public static IResourceBuilder<DevTunnelResource> WithReference<TResource>(
this IResourceBuilder<DevTunnelResource> tunnelBuilder,
IResourceBuilder<TResource> resourceBuilder,
bool allowAnonymous)
{
// ...
}
}
tunnelBuilder IResourceBuilder<DevTunnelResource> The resource builder.
resourceBuilder IResourceBuilder<TResource> The resource builder for the referenced resource.
allowAnonymous bool Whether anonymous access is allowed.
IResourceBuilder<DevTunnelResource> The resource builder.
WithReference(IResourceBuilder<DevTunnelResource>, IResourceBuilder<TResource>, DevTunnelPortOptions?) Section titled WithReference(IResourceBuilder<DevTunnelResource>, IResourceBuilder<TResource>, DevTunnelPortOptions?) extension IResourceBuilder<DevTunnelResource>
Adds ports on the dev tunnel for all endpoints found on the referenced resource.
public static class DevTunnelsResourceBuilderExtensions
{
public static IResourceBuilder<DevTunnelResource> WithReference<TResource>(
this IResourceBuilder<DevTunnelResource> tunnelBuilder,
IResourceBuilder<TResource> resourceBuilder,
DevTunnelPortOptions? portOptions = null)
{
// ...
}
}
tunnelBuilder IResourceBuilder<DevTunnelResource> The resource builder.
resourceBuilder IResourceBuilder<TResource> The resource builder for the referenced resource.
portOptions DevTunnelPortOptions? optional Options for the dev tunnel ports.
IResourceBuilder<DevTunnelResource> The resource builder.
To expose only specific endpoints on the referenced resource, use DevTunnelsResourceBuilderExtensions.WithReference.
WithReference(IResourceBuilder<DevTunnelResource>, EndpointReference) Section titled WithReference(IResourceBuilder<DevTunnelResource>, EndpointReference) extension IResourceBuilder<DevTunnelResource>
Exposes the specified endpoint via the dev tunnel.
public static class DevTunnelsResourceBuilderExtensions
{
public static IResourceBuilder<DevTunnelResource> WithReference(
this IResourceBuilder<DevTunnelResource> tunnelBuilder,
EndpointReference targetEndpoint)
{
// ...
}
}
tunnelBuilder IResourceBuilder<DevTunnelResource> The resource builder.
targetEndpoint EndpointReference The endpoint to expose via the dev tunnel.
IResourceBuilder<DevTunnelResource> The resource builder.
WithReference(IResourceBuilder<DevTunnelResource>, EndpointReference, bool) Section titled WithReference(IResourceBuilder<DevTunnelResource>, EndpointReference, bool) extension IResourceBuilder<DevTunnelResource>
Exposes the specified endpoint via the dev tunnel and sets whether anonymous access is allowed.
public static class DevTunnelsResourceBuilderExtensions
{
public static IResourceBuilder<DevTunnelResource> WithReference(
this IResourceBuilder<DevTunnelResource> tunnelBuilder,
EndpointReference targetEndpoint,
bool allowAnonymous)
{
// ...
}
}
tunnelBuilder IResourceBuilder<DevTunnelResource> The resource builder.
targetEndpoint EndpointReference The endpoint to expose via the dev tunnel.
allowAnonymous bool Whether anonymous access is allowed.
IResourceBuilder<DevTunnelResource> The resource builder.
WithReference(IResourceBuilder<DevTunnelResource>, EndpointReference, DevTunnelPortOptions?) Section titled WithReference(IResourceBuilder<DevTunnelResource>, EndpointReference, DevTunnelPortOptions?) extension IResourceBuilder<DevTunnelResource>
Exposes the specified endpoint via the dev tunnel.
public static class DevTunnelsResourceBuilderExtensions
{
public static IResourceBuilder<DevTunnelResource> WithReference(
this IResourceBuilder<DevTunnelResource> tunnelBuilder,
EndpointReference targetEndpoint,
DevTunnelPortOptions? portOptions)
{
// ...
}
}
tunnelBuilder IResourceBuilder<DevTunnelResource> The resource builder.
targetEndpoint EndpointReference The endpoint to expose via the dev tunnel.
portOptions DevTunnelPortOptions? Options for the dev tunnel port.
IResourceBuilder<DevTunnelResource> The resource builder.
WithReference(IResourceBuilder<TResource>, IResourceBuilder<IResourceWithEndpoints>, IResourceBuilder<DevTunnelResource>) Section titled WithReference(IResourceBuilder<TResource>, IResourceBuilder<IResourceWithEndpoints>, IResourceBuilder<DevTunnelResource>) extension IResourceBuilder<TResource>
Injects service discovery and endpoint information as environment variables from the dev tunnel resource into the destination resource, using the tunneled resource's name as the service name. Each endpoint defined on the target resource will be injected using the format defined by the ApplicationModel.ReferenceEnvironmentInjectionAnnotation on the destination resource, i.e. either "services__{sourceResourceName}__{endpointName}__{endpointIndex}={uriString}" for .NET service discovery, or "{RESOURCE_ENDPOINT}={uri}" for endpoint injection.
public static class DevTunnelsResourceBuilderExtensions
{
public static IResourceBuilder<TResource> WithReference<TResource>(
this IResourceBuilder<TResource> builder,
IResourceBuilder<IResourceWithEndpoints> targetResource,
IResourceBuilder<DevTunnelResource> tunnelResource)
{
// ...
}
}
builder IResourceBuilder<TResource> The builder.
targetResource IResourceBuilder<IResourceWithEndpoints> The resource to inject service discovery information for.
tunnelResource IResourceBuilder<DevTunnelResource> The dev tunnel resource to resolve the tunnel address from.
IResourceBuilder<TResource> The builder.
Referencing a dev tunnel will delay the start of the resource until the referenced dev tunnel's endpoint is allocated.