Visual Studio 2010で新しいWindowsサービスを作成すると、InstallUtilを使用してサービスを実行するように開始することを示すメッセージが表示されます。
次の手順を試しました。
1。 新しいプロジェクトファイルを作成->新規->プロジェクト-> Windowsサービス。 2。 プロジェクト名:TestService。 3。 そのままプロジェクトを構築します(Service1コンストラクター、OnStart、OnStop)。 4。 コマンドプロンプトを開き、 "C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ InstallUtil.exe" TestService.exe を実行します。 5。 net start TestService を実行します。
ステップ4の出力。
トランザクションインストールを実行します。 。 インストールのインストールフェーズを開始します。 。 ログファイルの内容を参照してください。 C:\ Users \ myusername \ Documents \ Visual Studio。 2010 \ Projects \ TestService \ TestService \ obj \ x86 \ Debug \ TestService.exe。 アセンブリの進捗状況。 。 ファイルはC:\ Users \ myusername \ Documents \ Visual Studioにあります。 2010 \ Projects \ Tes。 tService \ TestService \ obj \ x86 \ Debug \ TestService.InstallLog。 。 アセンブリ 'C:\ Users \ myusername \ Documents \ Visual Studioのインストール。 2010 \ Projects \ TestS ervice \ TestService \ obj \ x86 \ Debug \ TestService.exe '。 。 影響を受けるパラメーターは次のとおりです。 。 logtoconsole =。 。 logfile = C:\ Users \ myusername \ Documents \ Visual Studio。 2010 \ Projects \ TestService \ T。 estService \ obj \ x86 \ Debug \ TestService.InstallLog。 。 アセンブリパス= C:\ Users \ myusername \ Documents \ Visual Studio。 2010 \ Projects \ TestServ ice \ TestService \ obj \ x86 \ Debug \ TestService.exe。 。 RunInstallerAttribute.Yes属性を持つパブリックインストーラーはありません。 C:\ Users \ myusername \ Documents \ Visual Studioにあります。 2010 \ Projects \ TestService \ TestSe rvice \ obj \ x86 \ Debug \ TestService.exe。 組み立て。 。 インストールフェーズが正常に完了し、コミットフェーズが完了しました。 開始。 。 ログファイルの内容を参照してください。 C:\ Users \ myusername \ Documents \ Visual Studio。 2010 \ Projects \ TestService \ TestService \ obj \ x86 \ Debug \ TestService.exe。 アセンブリの進捗状況。 。 ファイルはC:\ Users \ myusername \ Documents \ Visual Studioにあります。 2010 \ Projects \ Tes。 tService \ TestService \ obj \ x86 \ Debug \ TestService.InstallLog。 。 コミットアセンブリ 'C:\ Users \ myusername \ Documents \ Visual Studio。 2010 \ Projects \ TestS ervice \ TestService \ obj \ x86 \ Debug \ TestService.exe '。 。 影響を受けるパラメーターは次のとおりです。 。 logtoconsole =。 。 logfile = C:\ Users \ myusername \ Documents \ Visual Studio。 2010 \ Projects \ TestService \ T。 estService \ obj \ x86 \ Debug \ TestService.InstallLog。 。 アセンブリパス= C:\ Users \ myusername \ Documents \ Visual Studio。 2010 \ Projects \ TestServ ice \ TestService \ obj \ x86 \ Debug \ TestService.exe。 。 RunInstallerAttribute.Yes属性を持つパブリックインストーラーはありません。 C:\ Users \ myusername \ Documents \ Visual Studioにあります。 2010 \ Projects \ TestService \ TestSe rvice \ obj \ x86 \ Debug \ TestService.exe。 組み立て。 。 インストーラーがないため、InstallStateファイルを削除します。 。 コミットフェーズは正常に完了しました。 。 トランザクションされたインストールが完了しました。
ステップ5の出力。
サービス名は無効です。
NET HELPMSG 2185と入力すると、さらにヘルプを利用できます。
デザイナーでService.csファイルを開き、右クリックしてメニューオプション[インストーラーの追加]を選択する必要があります。
すぐにインストールされません。.. 最初にインストーラクラスを作成する必要があります。
サービスインストーラーに関するいくつかの参照:。
かなり古い。.. しかし、これは私が話していることです:
C#のWindowsサービス:インストーラーの追加(パート3)。
これにより、「ProjectInstaller.cs」がオートマチックに作成されます。 次に、これをダブルクリックしてデザイナーに入り、コンポーネントを構成できます。
-serviceInstaller1
にはサービス自体のプロパティがあります。 Description
、 DisplayName
、 ServiceName
、および StartType
が最も重要です。
-serviceProcessInstaller1
には、この重要なプロパティがあります。 Account
は、サービスが実行されるアカウントです。
例:
this.serviceProcessInstaller1.Account = ServiceAccount.LocalSystem;
見る:
RunInstallerAttribute.Yes属性を持つパブリックインストーラーは、C:\ Users \ myusername \ Documents \ Visual Studio 2010 \ Projects \ TestService \ TestSe rvice \ obj \ x86 \ Debug \ TestService.exeアセンブリで見つかりませんでした。
コードにインストーラークラスがない可能性があります。 これは、実行可能ファイルをサービスとしてインストールする方法を「installutil」に指示する「Installer」から継承するクラスです。
PS. 私はここに、自己インストール/デバッグ可能なWindowsサービステンプレートをいくつか持っています。これらのテンプレートは、コードをコピーまたは使用できます:デバッグ可能、自己インストールWindowsサービス。
インストーラーを作成してそのエラーメッセージを取り除く別の方法を次に示します。 また、VS2015 Expressには「インストーラーの追加」メニュー項目がないようです。
クラスを作成して、以下のコードを追加し、参照System.Configuration.Install.dllを追加するだけです。
using System.Configuration.Install;
using System.ServiceProcess;
using System.ComponentModel;
namespace SAS
{
[RunInstaller(true)]
public class MyProjectInstaller : Installer
{
private ServiceInstaller serviceInstaller1;
private ServiceProcessInstaller processInstaller;
public MyProjectInstaller()
{
// Instantiate installer for process and service.
processInstaller = new ServiceProcessInstaller();
serviceInstaller1 = new ServiceInstaller();
// The service runs under the system account.
processInstaller.Account = ServiceAccount.LocalSystem;
// The service is started manually.
serviceInstaller1.StartType = ServiceStartMode.Manual;
// ServiceName must equal those on ServiceBase derived classes.
serviceInstaller1.ServiceName = "SAS Service";
// Add installer to collection. Order is not important if more than one service.
Installers.Add(serviceInstaller1);
Installers.Add(processInstaller);
}
}
}
2つの典型的な問題:
1。 ProjectInstallerクラスが欠落しています(@MiguelAngeloが指摘したように)。 2。 コマンドプロンプトは「管理者として実行」する必要があります。
別の考えられる問題(私が遭遇した):
ProjectInstaller
クラスが public
であることを確認してください。 正直なところ、どのように正確に実行したかはわかりませんが、次のようなイベントハンドラを ProjectInstaller.Designer.cs
に追加しました。
this.serviceProcessInstaller1.BeforeInstall + = new System.Configuration.Install.InstallEventHandler(this.serviceProcessInstaller1_BeforeInstall);
。
ProjectInstaller.cs
でハンドラー関数を作成する自動プロセス中に、クラスの定義が変更されたと思います。
パブリッククラスProjectInstaller:System.Configuration.Install.Installer
。
に。
部分クラスProjectInstaller:System.Configuration.Install.Installer
。
置換「パブリック」キーワードを「部分」に置き換えます。 したがって、それを修正するには、そうでなければなりません。
パブリックパーシャルクラスProjectInstaller:System.Configuration.Install.Installer
。
Visual Studio 2013 Community editionを使用しています。
VS 2010および.NET 4.0以降のステルス変更。
.NETにはエイリアスの変更またはコンパイラのクリーンアップがあり、特定のケースに対するこの小さな調整が明らかになる場合があります。
次のコードがある場合...
RunInstaller(true) // old alias
更新する必要がある場合があります。
RunInstallerAttribute(true) // new property spelling
これは、コンパイル時または実行時にカバーの下で変更されたエイリアスのようなものであり、このエラー動作を取得します。 上記のRunInstallerAttribute(true)への明示的な変更により、すべてのマシンのすべてのインストールシナリオで修正されました。
プロジェクトまたはサービスのインストーラーを追加したら、「古い」RunInstaller(true)を確認し、新しいRunInstallerAttribute(true)に変更します。