Aspire.Hosting.Azure.Sql 13.1.0

Prefix Reserved
dotnet add package Aspire.Hosting.Azure.Sql --version 13.1.0
                    
NuGet\Install-Package Aspire.Hosting.Azure.Sql -Version 13.1.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="Aspire.Hosting.Azure.Sql" Version="13.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aspire.Hosting.Azure.Sql" Version="13.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Aspire.Hosting.Azure.Sql" />
                    
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 Aspire.Hosting.Azure.Sql --version 13.1.0
                    
#r "nuget: Aspire.Hosting.Azure.Sql, 13.1.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 Aspire.Hosting.Azure.Sql@13.1.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=Aspire.Hosting.Azure.Sql&version=13.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Aspire.Hosting.Azure.Sql&version=13.1.0
                    
Install as a Cake Tool

Aspire.Hosting.Azure.Sql library

Provides extension methods and resource definitions for an Aspire AppHost to configure Azure SQL DB.

Getting started

Prerequisites

Install the package

Install the Aspire Azure SQL Server Hosting library with NuGet:

dotnet add package Aspire.Hosting.Azure.Sql

Configure Azure Provisioning for local development

Adding Azure resources to the Aspire application model will automatically enable development-time provisioning for Azure resources so that you don't need to configure them manually. Provisioning requires a number of settings to be available via .NET configuration. Set these values in user secrets in order to allow resources to be configured automatically.

{
    "Azure": {
      "SubscriptionId": "<your subscription id>",
      "ResourceGroupPrefix": "<prefix for the resource group>",
      "Location": "<azure location>"
    }
}

NOTE: Developers must have Owner access to the target subscription so that role assignments can be configured for the provisioned resources.

Usage example

In the AppHost.cs file of AppHost, register a SqlServer database and consume the connection using the following methods:

var sql = builder.AddAzureSqlServer("sql")
                 .AddDatabase("sqldata");

var myService = builder.AddProject<Projects.MyService>()
                       .WithReference(sql);

The WithReference method configures a connection in the MyService project named sqldata. In the Program.cs file of MyService, the sql connection can be consumed using the client library Aspire.Microsoft.Data.SqlClient:

builder.AddSqlServerClient("sqldata");

Connection Properties

When you reference Azure SQL Server resources using WithReference, the following connection properties are made available to the consuming project:

Azure SQL Server resource

The Azure SQL Server resource exposes the following connection properties:

Property Name Description
Host The fully qualified domain name of the Azure SQL Server
Port The SQL Server port (1433 for Azure)
Uri The connection URI, with the format mssql://{Host}:{Port}
JdbcConnectionString JDBC connection string with the format jdbc:sqlserver://{Host}:{Port};encrypt=true;trustServerCertificate=false;

Azure SQL database resource

The Azure SQL database resource inherits all properties from its parent Azure SQL Server resource and adds:

Property Name Description
DatabaseName The name of the database
Uri The connection URI, with the format mssql://{Host}:{Port}/{DatabaseName}
JdbcConnectionString JDBC connection string with the format jdbc:sqlserver://{Host}:{Port};database={DatabaseName};encrypt=true;trustServerCertificate=false;

Aspire exposes each property as an environment variable named [RESOURCE]_[PROPERTY]. For instance, the Uri property of a resource called db1 becomes DB1_URI. The client should add a valid authentication property for the JDBC connection string like authentication=ActiveDirectoryDefault or authentication=ActiveDirectoryManagedIdentity.

Azure SQL DB defaults

Unless otherwise specified, the Azure SQL DB created will be a 2vCores General Purpose Serverless database (GP_S_Gen5_2) with the free offer enabled.

Read more about the free offer here: Deploy Azure SQL Database for free

The free offer is configured so that when the maximum usage limit is reached, the database is stopped to avoid incurring in unexpected costs.

If you don't want to use the free offer and instead deploy the database use the default sku set by Azure, use the WithAzureDefaultSku method:

var sql = builder.AddAzureSqlServer("sql")
                 .AddDatabase("db", "my-db-name")
                 .WithAzureDefaultSku();

Setting a specific SKU

If you want to manually define what SKU must be used when deploying the Azure SQL DB resource, use the ConfigureInfrastructure method:

var sqlSrv = builder.AddAzureSqlServer("sqlsrv")
    .ConfigureInfrastructure(infra => {
        var azureResources = infra.GetProvisionableResources();
        var azureDb = azureResources.OfType<SqlDatabase>().Single();
        azureDb.Sku = new SqlSku() { Name = "HS_Gen5_2" };
    })
    .AddDatabase("sqldb", "DatabaseName");
    .RunAsContainer();

Additional documentation

Feedback & contributing

https://github.com/dotnet/aspire

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 is compatible.  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 is compatible.  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 (2)

Showing the top 2 NuGet packages that depend on Aspire.Hosting.Azure.Sql:

Package Downloads
Extensions.Aspire.SqlServer

Extensions for SQL Server Aspire integration

Toxic.Aspire

Contains sensible conventions and utilities for Aspire projects that are deployed to Azure.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Aspire.Hosting.Azure.Sql:

Repository Stars
rstropek/Samples
SSWConsulting/SSW.CleanArchitecture
SSW Clean Architecture Template
Version Downloads Last Updated
13.1.0 34,653 12/17/2025
13.0.2 11,345 12/4/2025
13.0.1 5,703 11/26/2025 13.0.1 is deprecated because it is no longer maintained.
13.0.0 18,564 11/11/2025 13.0.0 is deprecated because it is no longer maintained.
9.5.2 27,217 10/23/2025 9.5.2 is deprecated because it is no longer maintained.
9.5.1 23,126 10/3/2025 9.5.1 is deprecated because it is no longer maintained.
9.5.0 8,689 9/25/2025 9.5.0 is deprecated because it is no longer maintained.
9.4.2 13,473 9/2/2025 9.4.2 is deprecated because it is no longer maintained.
9.4.1 11,399 8/12/2025 9.4.1 is deprecated because it is no longer maintained.
9.4.0 10,603 7/29/2025 9.4.0 is deprecated because it is no longer maintained.
9.3.2 21,721 6/20/2025 9.3.2 is deprecated because it is no longer maintained.
9.3.1 8,377 6/10/2025 9.3.1 is deprecated because it is no longer maintained.
9.3.0 21,353 5/19/2025 9.3.0 is deprecated because it is no longer maintained.
9.2.1 10,321 4/24/2025 9.2.1 is deprecated because it is no longer maintained.
9.2.0 8,270 4/10/2025 9.2.0 is deprecated because it is no longer maintained.
9.1.0 38,818 2/25/2025 9.1.0 is deprecated because it is no longer maintained.
9.0.0 35,375 11/12/2024 9.0.0 is deprecated because it is no longer maintained.
9.0.0-rc.1.24511.1 1,055 10/15/2024 9.0.0-rc.1.24511.1 is deprecated because it is no longer maintained.
8.2.2 5,492 10/24/2024 8.2.2 is deprecated because it is no longer maintained.
8.2.1 5,455 9/26/2024 8.2.1 is deprecated because it is no longer maintained.
8.2.0 15,081 8/29/2024 8.2.0 is deprecated because it is no longer maintained.
8.1.0 4,061 7/23/2024 8.1.0 is deprecated because it is no longer maintained.
8.0.2 2,926 6/28/2024 8.0.2 is deprecated because it is no longer maintained.
8.0.1 3,417 5/21/2024 8.0.1 is deprecated because it is no longer maintained.
8.0.0 582 5/21/2024 8.0.0 is deprecated because it is no longer maintained.
8.0.0-preview.7.24251.11 677 5/7/2024 8.0.0-preview.7.24251.11 is deprecated because it is no longer maintained.
8.0.0-preview.6.24214.1 687 4/23/2024 8.0.0-preview.6.24214.1 is deprecated because it is no longer maintained.
8.0.0-preview.5.24201.12 908 4/9/2024 8.0.0-preview.5.24201.12 is deprecated because it is no longer maintained.