Locally.Aspire.Client 0.2.0

dotnet add package Locally.Aspire.Client --version 0.2.0
                    
NuGet\Install-Package Locally.Aspire.Client -Version 0.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Locally.Aspire.Client" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Locally.Aspire.Client" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Locally.Aspire.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Locally.Aspire.Client --version 0.2.0
                    
#r "nuget: Locally.Aspire.Client, 0.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Locally.Aspire.Client@0.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Locally.Aspire.Client&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Locally.Aspire.Client&version=0.2.0
                    
Install as a Cake Tool

Locally.Aspire.Client

This package allows connecting the Azure SDK clients of a (.Net) Aspire application application to Locally Build.

This can be done by adding the builder.UseLocallyCredential() method:

var builder = WebApplication.CreateBuilder(args);
builder.UseLocallyCredential();

builder.AddAzureBlobContainerClient("entries");
builder.AddAzureQueue("submissions");
builder.AddRedisClientBuilder("cache").WithOutputCache();

And then launching your application via locally run, e.g.:

locally run dotnet run

This package can be used in conjunction with Locally.Aspire.Hosting, which allows you to provision the Azure resources that these clients need within Locally.

What it does

  • Support for configuring Instance Discovery via an environment variable: enables making this configurable via an environment variable (AZURE_DISABLE_INSTANCE_DISCOVERY). Instance Discovery is used to validate that an Azure Environment (like Azure Public, Azure China, etc) is known and operated by Microsoft (by reaching out to login.microsoftonline.com) - which isn't the case for a local Azure emulator like Locally Build (and so this needs to be disabled). The Azure.Identity library for .NET doesn't currently read this variable, however LocallyCredential does.
  • Every Azure client: UseLocallyCredential() makes LocallyCredential the default credential for every client built by Microsoft.Extensions.Azure (which includes Aspire's Azure client integrations). Outside of locally run this is the same DefaultAzureCredential which these clients would have used anyway - which on App Service means the app's Managed Identity.
  • Redis: Aspire's WithAzureAuthentication() only signs in to caches using Azure's own host names, as such UseLocallyCredential() signs in to Locally's caches using a Microsoft Entra token. This applies to any connection to a *.locally host which uses TLS and has no password.

Using a real Azure resource

To use a real Azure resource alongside Locally, give that client its own credential - which takes precedence over UseLocallyCredential(), like so:

var azure = new ClientSecretCredential(tenantId, clientId, clientSecret,
    new ClientSecretCredentialOptions { AuthorityHost = AzureAuthorityHosts.AzurePublicCloud });

builder.AddAzureBlobContainerClient("archive", settings => settings.Credential = azure);

Note that you'll need to specify Microsoft Entra ID's authority host (as above), since under locally run Azure.Identity's credentials sign in to wherever AZURE_AUTHORITY_HOST points (which is Locally) - and the same applies to the Azure CLI and DefaultAzureCredential.

Clients it can't reach

Some clients don't use Microsoft.Extensions.Azure - as such you'll need to give these a LocallyCredential yourself:

// Aspire's PostgreSQL, Cosmos DB and App Configuration clients create their own credential.
builder.AddAzureNpgsqlDataSource("db", settings => settings.Credential = new LocallyCredential());
builder.AddAzureCosmosClient("cosmos", settings => settings.Credential = new LocallyCredential());
builder.AddAzureAppConfiguration("config", settings => settings.Credential = new LocallyCredential());

// Clients you construct yourself.
var blobs = new BlobServiceClient(endpoint, new LocallyCredential());

Microsoft.Data.SqlClient signs in using a credential of its own when the connection string specifies Authentication="Active Directory Default" (as Aspire's Azure SQL connection strings do) - as such you'll want to remove that and sign in using a LocallyCredential instead:

var credential = new LocallyCredential();
var connectionString = new SqlConnectionStringBuilder(builder.Configuration.GetConnectionString("db"));
connectionString.Remove("Authentication");

await using var connection = new SqlConnection(connectionString.ConnectionString)
{
    AccessTokenCallback = async (context, cancellationToken) =>
    {
        var token = await credential.GetTokenAsync(
            new TokenRequestContext([context.Resource.TrimEnd('/') + "/.default"]), cancellationToken);
        return new SqlAuthenticationToken(token.Token, token.ExpiresOn);
    },
};
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0 60 11/5/2026
0.1.0 72 11/4/2026