1

アプリケーションのインストール時に実行される System.Configuration.Install.Installer を拡張する があります。MSI ファイルに設定されているいくつかのプロパティにアクセスする必要があります (たとえば、INSTALLDIR、および取得する必要があるその他のパス)。ヘルパー アセンブリ内から MSI プロパティにアクセスする方法はありますか?

インストーラーは WiX 3.5 を使用して構築されていることに注意してください。

これについてご支援いただきありがとうございます。

編集これがクラスの現在のコードです。

[RunInstaller(true)]
   public class MxServeInstaller : Installer
   {
      private ServiceInstaller myServiceInstaller;
      private ServiceProcessInstaller myServiceProcessInstaller;

      public MyProductInstaller()
      {
         this.myServiceInstaller = new ServiceInstaller();
         this.myServiceInstaller.StartType = ServiceStartMode.Automatic;
         this.myServiceInstaller.ServiceName = MyProduct.SERVICE_NAME;
         this.myServiceInstaller.Description = "Provides software copy protection and token pool management services for the Mx-Suite from Company";
         this.myServiceInstaller.ServicesDependedOn = new string[] { "Crypkey License" };

         Installers.Add(this.myServiceInstaller);

         this.myServiceProcessInstaller = new ServiceProcessInstaller();
         this.myServiceProcessInstaller.Account = ServiceAccount.LocalSystem;         
         Installers.Add(this.myServiceProcessInstaller);
      }

      public override void Install(System.Collections.IDictionary stateSaver)
      {
         base.Install(stateSaver);
         ServiceController controller = new ServiceController(MyProduct.SERVICE_NAME);
         try
         {
            controller.Start();
         }
         catch( Exception ex )
         {
            string source = "My-Product Installer";
            string log = "Application";
            if (!EventLog.SourceExists(source))
               EventLog.CreateEventSource(source, log);

            EventLog eventLog = new EventLog();
            eventLog.Source = source;
            eventLog.WriteEntry(string.Format("Failed to start My-Product!{1}", ex.Message), EventLogEntryType.Error);
         }
      }
   }

私が追加しようとしているのは、少なくともインストーラーで設定された INSTALLDIR プロパティを知る必要がある AfterInstall のフェーズです。

4

1 に答える 1

1

インストーラー クラスのカスタム アクションはアウト プロセスで実行され、MSI ハンドルや関連する関数 (プロパティの取得/設定、ログ記録など) に直接アクセスすることはできません。

解決策は、代わりに Windows Installer XML Deployment Tools Foundation カスタム アクション ( google WiX DTF ) を使用することです。これは、マネージ コード カスタム アクションのはるかに優れたパターンであり、ホスティング モデルを変更するだけで、MSI と通信できるようにセッション クラスを提供します。コードの残りの部分はボックスに収まるはずです。

ただし、さらに指摘する必要があります....カスタムアクションに実際にカスタムアクションを必要とするものは何もありません。あなたの本当の問題は、Visual Studio 展開プロジェクトが MSI の組み込みの Windows サービスを作成および開始する機能を隠していることです。

EventSource 拡張機能と ServiceInstall / ServiceControl 要素を使用してカスタム アクションをまったく使用せずにこのすべての作業を行う WiX マージ モジュールの作成方法に関するアイデアについては、これらのブログ記事を参照してください。これにより、Visual Studio 展開プロジェクトに追加できるマージ モジュールが作成されます。

Visual Studio 展開プロジェクトの引き換え

Windows Installer XML を使用した InstallShield の拡張 - 証明書

そして最後に、これを行うことが重要な理由:

ザタオカ: カスタム アクションは (一般的に) 失敗を認めることです。

于 2012-08-30T14:30:42.120 に答える