DacFx DeploymentPlanExecutor OnExecute not called

点点圈 提交于 2019-12-04 04:59:37

问题


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:


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

dacDeployOptions.RunDeploymentPlanExecutors = true;



来源:https://stackoverflow.com/questions/35198261/dacfx-deploymentplanexecutor-onexecute-not-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!