2016-02-04 40 views
1

我試圖使用Microsofts DacFx 3.0編程自定義DeploymentPlanExecutor,但是OnExecute-方法從未被調用。DacFx DeploymentPlanExecutor OnExecute未調用

  • 如果我使用相同的DeploymentPlanModifier而不是OnExecute()按預期調用。
  • 無論是添加執行程序,修改程序還是兩者,DAC實際上都已成功部署到數據庫。
  • 執行人似乎在部署過程中得到認可,因爲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); 
} 

回答

2

的問題是,你必須明確地告訴DacFx使用執行程序。儘管默認情況下啓用了修飾符。

dacDeployOptions.RunDeploymentPlanExecutors = true;