c# - 未调用 DacFx DeploymentPlanExecutor OnExecute

标签 c# deployment dacpac dac

我正在尝试使用 Microsofts DacFx 3.0 编写自定义 DeploymentPlanExecutor,但从未调用 OnExecute 方法。

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

不幸的是,我找不到任何使用 DeploymentPlanExecutor 的示例(只有使用 DeploymentPlanModifier 的示例)并且 DacFx 的文档根本没有帮助。

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

我的 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);
}

最佳答案

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

dacDeployOptions.RunDeploymentPlanExecutors = true;

关于c# - 未调用 DacFx DeploymentPlanExecutor OnExecute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35198261/

相关文章:

c# - LINQ 查询抛出 InvalidCastException?

c# - 以编程方式在 TabbedPage 中的选项卡之间切换

java - 如何增量更新Java EE Web应用程序?

javascript - Meteor Galaxy 部署失败 - 容器崩溃

C# 按 2 列对表进行排序

php - 如何将我的 Laravel 4 站点部署到 Windows Azure 上?

c# - 如何在 DacServices.Deploy() 中禁用部署前和部署后脚本

sql-server - SSDT 未解析的对象引用

C# DateTime 在内存中有 'Z',但在 SQL Db 中没有