このコード サンプルはMSDN Web サイトで見つけました。私の質問は、メイン メソッドでクラスをインスタンス化する最後の行に関するものです。しかし、それは必要ですか?Installutilのドキュメントによると:
Installutil.exe はリフレクションを使用して、指定されたアセンブリを検査し、System.ComponentModel.RunInstallerAttribute 属性が true に設定されているすべてのインストーラーの種類を見つけます。その後、ツールは Installer タイプの各インスタンスに対して Installer.Install または Installer.Uninstall メソッドを実行します。
ということは、main メソッドと MyEventLogInstaller クラスのインスタンス化は必要ないということですか?
using System;
using System.Configuration.Install;
using System.Diagnostics;
using System.ComponentModel;
[RunInstaller(true)]
public class MyEventLogInstaller: Installer
{
private EventLogInstaller myEventLogInstaller;
public MyEventLogInstaller()
{
// Create an instance of an EventLogInstaller.
myEventLogInstaller = new EventLogInstaller();
// Set the source name of the event log.
myEventLogInstaller.Source = "NewLogSource";
// Set the event log that the source writes entries to.
myEventLogInstaller.Log = "MyNewLog";
// Add myEventLogInstaller to the Installer collection.
Installers.Add(myEventLogInstaller);
}
public static void Main()
{
MyEventLogInstaller myInstaller = new MyEventLogInstaller();
}
}