DacFx DeploymentPlanExecutor OnExecute not called

2019-03-01 13:44发布

I'm trying to program a custom DeploymentPlanExecutor using Microsofts DacFx 3.0 but the OnExecute-Method is never called.

  • If I use an identical DeploymentPlanModifier instead, OnExecute() is called as expected.
  • No matter whether I add the Executor, the Modifier, or both, the DAC actually is successfully deployed to the Database.
  • The Executor seems to be recognized during the Deployment since OnApplyDeploymentConfiguration() is called

Unfortunately I wasn't able to find any examples that use an DeploymentPlanExecutor (only examples with DeploymentPlanModifier) and the documentation of DacFx does not help at all.

My question is, why is OnExecute() in the DeploymentPlanExecutor not called and how can I fix this?

The code for my DeploymentPlanExecutor and DeploymentPlanExecutor:

using System.Collections.Generic;
using Microsoft.SqlServer.Dac.Deployment;

namespace DacTest
{
    // The executor that does not work as expected
    [ExportDeploymentPlanExecutor(ContributorId, "1.0.0.0")] 
    public class Executor : DeploymentPlanExecutor
    {
        public const string ContributorId = "DacTest.Executor";

        protected override void OnApplyDeploymentConfiguration(DeploymentContributorContext context, ICollection<DeploymentContributorConfigurationStream> configurationStreams)
        {
            // Called
        }

        protected override void OnEstablishDeploymentConfiguration(DeploymentContributorConfigurationSetup setup)
        {
            // Not called
        }

        protected override void OnExecute(DeploymentPlanContributorContext context)
        {
            // Not called!
        }
    }

   // The modifier that does work as expected
   [ExportDeploymentPlanModifier(ContributorId, "1.0.0.0")] 
    public class Modifier : DeploymentPlanModifier
    {
        public const string ContributorId = "DacTest.Modifier";

        protected override void OnApplyDeploymentConfiguration(DeploymentContributorContext context, ICollection<DeploymentContributorConfigurationStream> configurationStreams)
        {
            // Called
        }

        protected override void OnEstablishDeploymentConfiguration(DeploymentContributorConfigurationSetup setup)
        {
            // Not called
        }

        protected override void OnExecute(DeploymentPlanContributorContext context)
        {
            // Called!
        }
    }
}

The code calling the deployment (has to be in a different assembly):

using (DacPackage dacpac = DacPackage.Load(@"C:\Temp\dac.dacpac"))
{
    DacDeployOptions dacDeployOptions = new DacDeployOptions();
    dacDeployOptions.AdditionalDeploymentContributors = Executor.ContributorId; // + ";" + Modifier.ContributorId;

    DacServices dacServices = new DacServices(connectionString);
    dacServices.Deploy(dacpac, databaseName, true, dacDeployOptions);
}

1条回答
Emotional °昔
2楼-- · 2019-03-01 14:06

The problem was, that you have to explicitly tell DacFx to use Executors. Modifiers are enabled by default though.

dacDeployOptions.RunDeploymentPlanExecutors = true;

查看更多
登录 后发表回答