Microsoft.Build.Sql 2.4.0-preview.2

Prefix Reserved
This is a prerelease version of Microsoft.Build.Sql.
<Sdk Name="Microsoft.Build.Sql" Version="2.4.0-preview.2" />
                    
For projects that support Sdk, copy this XML node into the project file to reference the package.
#:sdk Microsoft.Build.Sql@2.4.0-preview.2
                    
#:sdk 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.

Microsoft.Build.Sql

NuGet Version

The Microsoft.Build.Sql SDK contains MSBuild support for SQL, similar to Microsoft.NET.Sdk for .NET projects.

Overview

Your database objects are stored as code with Microsoft.Build.Sql SDK-style SQL projects. SQL database objects are aggregated from the .sql files in the project and dotnet build generates a .dacpac artifact for deploying the objects dynamically to a database. Development environment integrations are available for VS Code and Visual Studio:

SQL code analysis and other build-time tests can validate database code quality and correctness during continuous integration of code changes. Leverage the Microsoft.SqlPackage .NET tool for deploying objects to databases and updating a project with the contents of a project.

Get started

The Microsoft.Build.Sql SDK requires .NET 8 or higher.

New project

.NET templates are available for quickly setting up a new SQL project. Install the Microsoft.Build.Sql.Templates NuGet package to get started with a new SQL project.

dotnet new -i Microsoft.Build.Sql.Templates

Create a new SQL project using the sqlproj template.

dotnet new sqlproj -n ProductsTutorial

Any .sql files added to the project folder will be included in the build process and generate a .dacpac file. The .dacpac file can be used to deploy the database objects to a database.

From an existing database

An existing database can be scripted out into a SQL project using the Microsoft.SqlPackage .NET tool. The following command will generate a SQL project from an existing database.

sqlpackage /a:Extract /tf:YourProjectFolder /scs:"Data Source=yourservername;Initial Catalog=yourdatabasename;Authentication=Active Directory Interactive" /p:ExtractTarget=SchemaObjectType

Use the Microsoft.Build.Sql.Templates as outlined above to create a new SQL project file for the .sql files generated by the sqlpackage tool.

Convert an existing SQL project

Depending on the complexity of your project, the conversion to a Microsoft.Build.Sql project may be straightforward. Building the project before the process and retaining the .dacpac for comparison after the conversion is highly recommended. The primary step in the conversion is to add the SDK reference. Edit the .sqlproj file by adding

<Sdk Name="Microsoft.Build.Sql" Version="2.4.0-preview.2" />

inside the <Project> tag.

Depending on where you are developing, additional steps may be required. A walk-through of the conversion process is available at https://learn.microsoft.com/sql/tools/sql-database-projects/howto/convert-original-sql-project.

Inline C# SQLCLR compilation

On Windows, SQL projects can opt in to compiling inline C# SQLCLR sources with Visual Studio's .NET Framework MSBuild (MSBuild.exe). This mode is not supported by dotnet build. Target .NET Framework, not modern .NET:

<Project>
  <Sdk Name="Microsoft.Build.Sql" Version="2.4.0-preview.2" />
  <PropertyGroup>
    <EnableSqlClr>true</EnableSqlClr>
    <TargetFramework>net472</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Clr\**\*.cs" />
  </ItemGroup>
</Project>

From a Visual Studio Developer Command Prompt, run MSBuild.exe Database.sqlproj /restore /t:Build. The matching .NET Framework targeting pack must be installed or available through package restore. The build compiles the C# sources, generates the SQLCLR objects from their attributes, and embeds the assembly in the DACPAC. SQL files remain included by default.

Deploy the resulting DACPAC with SqlPackage; its runtime does not need to match the framework build host. The target SQL Server must already be configured to run the assembly under its CLR security policy. This option does not change server security settings or add modern-.NET SQLCLR runtime support.

Resources

Telemetry

The .NET SDK for SQL includes a telemetry feature that collects usage data and sends it to Microsoft when you use build commands. The usage data includes exception information when the build command fails. Telemetry data helps the .NET team understand how the tools are used so they can be improved. Information on failures helps the team resolve problems and fix bugs.

How to opt out

The .NET SDK for SQL telemetry feature is enabled by default for Microsoft distributions of the SDK. To opt out of the telemetry feature, set the DACFX_TELEMETRY_OPTOUT environment variable to 1 or true. Telemetry feature can also be opt out by opting out .NET SDK telemetry.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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
2.4.0-preview.2 192 11/17/2026
2.4.0-preview.1 302 10/16/2026
2.3.0 425,772 9/17/2026
2.3.0-preview.3 850 9/10/2026
2.3.0-preview.2 138,050 7/28/2026
2.3.0-preview.1 14,572 6/18/2026
2.2.0 937,052 6/3/2026
2.2.0-preview.3 2,053 5/11/2026
2.2.0-preview.2 4,321 5/4/2026
2.2.0-preview.1 5,467 4/3/2026
2.1.0 1,404,376 2/11/2026
2.1.0-preview.3 2,173 1/23/2026
2.1.0-preview.2 262 1/20/2026
2.1.0-preview.1 5,370 11/18/2025
2.0.0 1,740,844 10/15/2025
2.0.0-rc.1 10,118 10/6/2025
2.0.0-preview.5 47,491 9/26/2025
2.0.0-preview.4 22,735 8/29/2025
2.0.0-preview.3 13,985 8/1/2025
2.0.0-preview.2 25,783 6/3/2025
Loading failed