3

我正在尝试DeploymentPlanExecutor使用 Microsofts DacFx 3.0 编写自定义程序,但OnExecute从未调用过 -Method。

  • 如果我改用相同的DeploymentPlanModifierOnExecute()则按预期调用。
  • 无论我添加 Executor、Modifier 还是两者都添加,DAC 实际上已成功部署到数据库。
  • Executor 似乎在部署期间被识别,因为OnApplyDeploymentConfiguration()被称为

不幸的是,我找不到任何使用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);
}
4

1 回答 1

3

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

dacDeployOptions.RunDeploymentPlanExecutors = true;

于 2016-02-10T12:04:09.980 回答