dacdeploy 0.1.0
See the version list below for details.
dotnet tool install --global dacdeploy --version 0.1.0
dotnet new tool-manifest
dotnet tool install --local dacdeploy --version 0.1.0
#tool dotnet:?package=dacdeploy&version=0.1.0
nuke :add-package dacdeploy --version 0.1.0
dacdeploy
Plans and applies a SQL Server database project (.sqlproj) to a database, with DacFx. dacdeploy plan shows what
applying would change and can save that plan for review. dacdeploy apply then applies exactly the plan you reviewed,
and refuses it if the database or the project changed since.
On top of what a plain DacFx publish does:
- Saved plans are checked. A saved plan holds the SQL and a fingerprint of DacFx's deployment plan.
applyplans again and stops before running anything unless the fingerprint matches. A plan edited after it was saved, or made for another database, is refused. - Nothing outside the project is dropped by accident. Objects and columns the database has and the project doesn't
are kept and listed in every plan. A kept
NOT NULLcolumn without a default is made nullable, so inserts that leave it out keep working.--prunedrops them, in a plan of its own once nothing else is pending. - Data scripts run in the same deployment.
Data/*.sql(reference data) runs again whenever the file changes;Migrations/*.sql(one-offs) runs once. A one-off can split into a part that runs before the schema changes (--# pre) and one that runs after (--# post). Each run is recorded on the database, so the plan lists only the scripts still to run. - All or nothing. Schema changes and data scripts run in one transaction: a failure leaves the database as it was.
- Logins stay out of files.
dacdeploy loginsaves them in your OS credential store (Keychain, Windows Credential Manager, Secret Service).
Install
dotnet tool install --global dacdeploy
Or pin it per repository with a local tool manifest,
or with mise: mise use dotnet:dacdeploy.
dacdeploy needs .NET 8 or later, and the .NET SDK to build your project.
Set up a project
Put a dacdeploy.json next to your .sqlproj, naming the databases you deploy to:
{
"Environments": {
"prod": { "Server": "db.example.com", "Database": "Shop" },
"test": { "Server": "db-test.example.com", "Database": "ShopTest", "Variables": { "OtherDb": "OtherTest" } }
}
}
dacdeploy works on the dacdeploy.json in the current folder or the nearest folder above it. It also reads:
| Setting | Default |
|---|---|
Project |
the one .sqlproj next to dacdeploy.json |
PublishProfile |
the project's name with .publish.xml |
UserSecretsId |
none |
Paths are relative to dacdeploy.json. An environment's Variables are the SQLCMD variables to deploy with.
The publish profile holds how the project deploys. dacdeploy adds its own deployment contributors to it, and needs it
to set IncludeTransactionalScripts, so data scripts run in the deployment's transaction:
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IncludeTransactionalScripts>True</IncludeTransactionalScripts>
</PropertyGroup>
</Project>
Data scripts live next to the project, in Data/ and Migrations/. Name one-offs after the date they're written,
20261120-backfill-totals.sql, so they run in order. An SDK-style project builds every .sql file under its folder, so
leave the data scripts out of the build, and the plans you save there too:
<ItemGroup>
<Build Remove="Data/**;Migrations/**;**/*.plan.sql" />
<None Include="Data/**/*.sql;Migrations/**/*.sql" />
</ItemGroup>
Your own environments, and environment variables
Each source overrides the one before: dacdeploy.json, then your user secrets (when dacdeploy.json names a
UserSecretsId), then environment variables prefixed DACDEPLOY_. Add a local database to your user secrets:
dotnet user-secrets set --id <UserSecretsId> "Environments:dev:Server" "localhost,1433"
dotnet user-secrets set --id <UserSecretsId> "Environments:dev:Database" "Shop"
In CI, configure one with variables: DACDEPLOY_Environments__ci__Server, DACDEPLOY_Environments__ci__User,
DACDEPLOY_Environments__ci__Password.
Logins
An environment's login comes from its User and Password, or from your OS credential store:
dacdeploy login -E prod --read-only # used by plan and extract
dacdeploy login -E prod # the login that can write, used by apply
Logins are saved per server, so every environment on that server uses them. plan and extract prefer the read-only
login and fall back to the one that can write.
Use
dacdeploy plan -E prod --out release.plan.sql # build the project, show the plan, save it
dacdeploy apply -E prod release.plan.sql # apply the reviewed plan
Without a plan file, apply plans, shows the plan and asks before applying; --yes applies without asking.
| Command | Options |
|---|---|
plan |
--out <file>, --exit-code (exit 2 when there are changes), --prune, --verbose |
apply |
[<plan>], --yes, --prune, --verbose |
extract |
--write (replace the project's Schema/dbo with the database's schema), --verbose |
login |
--read-only |
Every command takes -E <environment>. dacdeploy <command> --help describes each one.
In tests
The DacDeploy.Core package holds what dacdeploy deploys with, for test fixtures that deploy a project the way
dacdeploy does:
var deployer = new Deployer(new DeploymentFiles(dacpacPath, profilePath, projectDirectory));
deployer.Deploy(new DeploymentTarget("test", server, database, variables, user, password));
| Product | Versions 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. |
This package has no dependencies.