Skip to content

ErikEJ/DacDeploySkip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dac Deploy Skip

Tool to determine if a deployment of a specific .dacpac file is required based on metadata present in the target database.

This can reduce your .dacpac deployment times significantly in scenarios you deploy the same .dacpac multiple times, e.g. in CI/CD pipelines.

Getting started

The tool runs on any system with the .NET 8 or .NET 10 runtime installed.

Installing the tool

dotnet tool install -g ErikEJ.DacFX.DacDeploySkip

Basic usage

dacdeployskip check "<path to .dacpac>" "SQL Server connection string" 

This command will return 0 if the .dacpac has already been deployed, otherwise 1.

dacdeployskip mark "<path to .dacpac>" "SQL Server connection string"

This command will add metadata to the target database to register the .dacpac as deployed.

You can use the optional -namekey parameter to use the name of the .dacpac file instead of the full path as key.

dacdeployskip mark "<path to .dacpac>" "SQL Server connection string" -namekey

Sample usage in Azure DevOps pipeline

trigger:
- main

pool:
  name: selfhosted

variables:
  buildConfiguration: 'Release'
  connectionString: 'Data Source=(localdb)\mssqllocaldb;Initial Catalog=TestBed;Integrated Security=true;Encrypt=false'
  dacpacPath: '$(Build.SourcesDirectory)\Database\bin\Release\net8.0\Database.dacpac'

steps:

  - powershell: |
      dotnet tool install -g Microsoft.SqlPackage
      dotnet tool install -g ErikEJ.DacFX.DacDeploySkip
      dotnet build $(buildConfiguration)
      dacdeployskip check "$(dacpacPath)" "$(connectionString)"
      if (!$?)
      {
         sqlpackage /Action:Publish /SourceFile:"$(dacpacPath)" /TargetConnectionString:"$(connectionString)"
         dacdeployskip mark "$(dacpacPath)" "$(connectionString)"
      }
    displayName: deploy dacpac if needed only

You can find a complete example here.

You can also use the tool to set a condition in your pipeline based on whether a deployment is needed or not. This can be useful if you use a task like SqlAzureDacpacDeployment or SqlDacpacDeploymentOnMachineGroup.

- powershell: |

    dacdeployskip check "$(dacpacPath)" "$(ConnectionString)"
    if (!$?)
    {
      Write-Host "##vso[task.setvariable variable=DeployDacPac;]$true"  
    }
    else
    {
      Write-Host "##vso[task.setvariable variable=DeployDacPac;]$false"  
    }
  displayName: check if dacpac deployment is needed

Then use the condition on subsequent tasks:

 condition: and(succeeded(), eq(variables['DeployDacPac'], true))

Using multiple deployments against the same database

If you deploy multiple different .dacpac files against the same database, use the additional parameter /p:DropExtendedPropertiesNotInSource=False to avoid dropping the metadata added by this tool.

If you use a publish profile, you can add the same parameter there.

<DropExtendedPropertiesNotInSource>False</DropExtendedPropertiesNotInSource>

About

.NET Tool to help speed up deployment time for SQL Database projects - .dacpac files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

 
 
 

Contributors

Languages