DacFx DeploymentPlanExecutor未调用OnExecute

时间:2016-02-04 10:18:16

标签: c# deployment dacpac dac

我正在尝试使用Microsofts DacFx 3.0编写自定义DeploymentPlanExecutor,但永远不会调用OnExecute - 方法。

  • 如果我改为使用相同的DeploymentPlanModifier,则按预期调用OnExecute()
  • 无论是否添加Executor,Modifier或两者,DAC实际上都已成功部署到数据库。
  • 自从OnApplyDeploymentConfiguration()被称为
  • 以来,部署期间似乎识别出Executor

很遗憾,我无法找到任何使用DeploymentPlanExecutor的示例(只有DeploymentPlanModifier的示例),DacFx的文档根本没用。

我的问题是,为什么OnExecute()中的DeploymentPlanExecutor未被调用,我该如何解决?

我的DeploymentPlanExecutorDeploymentPlanExecutor的代码:

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!
        }
    }
}

调用部署的代码(必须在不同的程序集中):

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 个答案:

答案 0 :(得分:2)

问题是,您必须明确告诉DacFx使用Executors。默认情况下,默认情况下会启用修改器。

dacDeployOptions.RunDeploymentPlanExecutors = true;