Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to package a deployment contributor in a dacpac?

I cannot find any references to how to package a deployment contributor in a dacpac.

  1. We are using DacServices.Deploy Method to deploy our databases as dacpacs to SQL Server.
  2. An argument to that method has a property DacDeployOptions.AdditionalDeploymentContributors which has the description "Specifies additional deployment contributors which should run - in addition to those specified in the dacpac [emphasis added]."

So my question is how does one specify these deployment contributors in the dacpac?

I tried putting the deployment contributor class in the SSDT project in Visual Studio, but that interferes with the CLR assemblies loaded into SQL Server (i.e., it gets loaded into SQL Server and if its dependencies are not also set to be loaded, an error is thrown).

Please advise. Thank-you.

like image 913
David Mercer Avatar asked Nov 09 '22 22:11

David Mercer


1 Answers

To put into the dacpac that you want a specific contributor loaded then you need to manually edit the .sqlproj file and add this:

<PropertyGroup>
    <DeploymentContributors>$(DeploymentContributors);AgileSqlClub.DeploymentPlanLogger</DeploymentContributors>
</PropertyGroup>

AFTER

<Import Condition="'$(SQLDBExtensionsRefPath)' != ''" Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.SqlTasks.targets" />

Change "AgileSqlClub.DeploymentPlanLogger" to whatever your contributor exports its name as (i.e. [ExportDeploymentPlanModifier("AgileSqlClub.DeploymentPlanLogger", "0.1.0.0")])

Adding this xml will cause your "Origin.xml" in your dacpac to have this:

<RequiredContributors>
  <DeploymentContributor Name="AgileSqlClub.DeploymentPlanLogger" Version="0.1.0.0" />
</RequiredContributors>

You are probably one of the only people who ever uses this feature so who knows if it works?? Let everyone know!

You will also need to deploy the contributor to the machine you are building your dacpac on and the machine you deploy or generate the deploy script from. On the machine you will deploy from:

The path that the dacfx looks to find deployment contributors is hard-coded to:

Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Microsoft SQL Server\120\DAC\bin\Extensions")

So on my system it is "c:\program files(x86)\Microsoft SQL Server\120\DAC\bin\Extensions".

On the machine you will use when you compile the dacpac you need it in the visual studio path that is in the link:

http://agilesqlclub.codeplex.com/wikipage?title=Deploying&referringTitle=Documentation

See the section "If you publish in SSDT":

(on my system with vs 2015 it is C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\120\Extensions)

One other thing is that when you copy your contributor to the extensions directories you can put them inside another folder so you can keep your extensions and whatever dependencies that has separate from any other contributors which will have its own set of dependencies (and dll hell dies with .net lol)

Out of interest what does your contributor do?

If it is OSS please consider sharing it:

https://github.com/DacFxDeploymentContributors/Contributors

Ed

like image 79
Ed Elliott Avatar answered Nov 14 '22 22:11

Ed Elliott