我正在尝试编写一个自定义程序DeploymentPlanExecutor
使用 Microsoft 的 DacFx 3.0 但OnExecute
-方法从未被调用。
- 如果我使用相同的
DeploymentPlanModifier
反而,OnExecute()
被按预期调用。
- 无论我添加执行器、修改器还是两者,DAC 实际上都已成功部署到数据库。
- 执行者似乎在部署过程中被识别,因为
OnApplyDeploymentConfiguration()
叫做
不幸的是我找不到任何使用的例子DeploymentPlanExecutor
(仅示例DeploymentPlanModifier
)并且 DacFx 的文档根本没有帮助。
我的问题是,为什么OnExecute()
in the DeploymentPlanExecutor
没有被调用,我该如何解决这个问题?
我的代码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!
}
}
}
调用部署的代码(必须位于不同的程序集中):
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);
}