我正在尝试使用Microsofts DacFx 3.0编写自定义DeploymentPlanExecutor
,但永远不会调用OnExecute
- 方法。
DeploymentPlanModifier
,则按预期调用OnExecute()
。 OnApplyDeploymentConfiguration()
被称为很遗憾,我无法找到任何使用DeploymentPlanExecutor
的示例(只有DeploymentPlanModifier
的示例),DacFx的文档根本没用。
我的问题是,为什么OnExecute()
中的DeploymentPlanExecutor
未被调用,我该如何解决?
我的DeploymentPlanExecutor
和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);
}
答案 0 :(得分:2)
问题是,您必须明确告诉DacFx使用Executors。默认情况下,默认情况下会启用修改器。
dacDeployOptions.RunDeploymentPlanExecutors = true;