143

Visual Studio 2010で新しいWindowsサービスを作成すると、InstallUtilとnetstartを使用してサービスを実行することを示すメッセージが表示されます。

次の手順を試しました。

  1. 新しいプロジェクトの作成ファイル->新規->プロジェクト->Windowsサービス
  2. プロジェクト名:TestService
  3. プロジェクトをそのままビルドする(Service1コンストラクター、OnStart、OnStop)
  4. コマンドプロンプトを開き、「C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319\InstallUtil.exe」TestService.exeを実行します
  5. netstartTestServiceを実行します。

ステップ4の出力

トランザクションインストールの実行。

インストールのインストールフェーズを開始します。

C:\ Users \ myusername \ Documents \ Visual Studio 2010 \ Projects \ TestService \ TestService \ obj \ x86 \ Debug \ TestService.exeアセンブリの進行状況については、ログファイルの内容を参照してください。

このファイルは、C:\ Users \ myusername \ Documents \ Visual Studio 2010 \ Projects \ TestService \ 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

assemblypath = 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 \ TestService \ 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 \ TestService \ 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

assemblypath = 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 \ TestService \ obj \ x86 \ Debug\TestService.exeアセンブリに見つかりませんでした。

インストーラーがないため、InstallStateファイルを削除します。

コミットフェーズは正常に完了しました。

トランザクションインストールが完了しました。

ステップ5の出力

サービス名が無効です。

NET HELPMSG 2185と入力すると、さらにヘルプが表示されます。

4

7 に答える 7

252

デザイナでService.csファイルを開き、それを右クリックして、メニューオプション[インストーラの追加]を選択する必要があります。

箱から出してすぐにインストールすることはできません...最初にインストーラークラスを作成する必要があります。

サービスインストーラーに関するいくつかのリファレンス:

方法:サービスアプリケーションにインストーラーを追加する

かなり古い...しかし、これは私が話していることです:

C#でのWindowsサービス:インストーラーの追加(パート3)

これにより、ProjectInstaller.csが自動的に作成されます。次に、これをダブルクリックしてデザイナーを入力し、コンポーネントを構成できます。

  • serviceInstaller1サービス自体のプロパティがあります:、、およびDescriptionが最も重要です。DisplayNameServiceNameStartType

  • serviceProcessInstaller1この重要なプロパティAccountがあります。それは、サービスが実行されるアカウントです。

例えば:

this.serviceProcessInstaller1.Account = ServiceAccount.LocalSystem;
于 2011-10-27T20:45:56.440 に答える
12

見つめている:

RunInstallerAttribute.Yes属性を持つパブリックインストーラーがC:\ Users \ myusername \ Documents \ Visual Studio 2010 \ Projects \ TestService \ TestService \ obj \ x86 \ Debug\TestService.exeアセンブリに見つかりませんでした。

コードにインストーラークラスが含まれていないようです。これは、実行可能ファイルをサービスとしてインストールする方法を示す、Installerそれを継承するクラスです。installutil

追伸私はここに自分の小さな自己インストール/デバッグ可能なWindowsサービステンプレートを持っています。これからコードをコピーしたり使用したりできます:デバッグ可能、自己インストールWindowsサービス

于 2011-10-27T20:45:18.797 に答える
9

インストーラーを作成してそのエラーメッセージを取り除く別の方法を次に示します。また、VS2015Expressには「インストーラーの追加」メニュー項目がないようです。

クラスを作成し、以下のコードを追加して、参照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);
        }
    }
}
于 2016-11-03T19:48:48.107 に答える
7

2つの典型的な問題:

  1. ProjectInstallerクラスがありません(@MiguelAngeloが指摘しているように)
  2. コマンドプロンプトは「管理者として実行」する必要があります</li>
于 2015-08-29T21:38:29.630 に答える
4

別の考えられる問題(私が遭遇した):

ProjectInstallerクラスがであることを確認してくださいpublic。正直なところ、どの程度正確に行ったかはわかりませんがProjectInstaller.Designer.cs、次のようにイベントハンドラーを追加しました。

this.serviceProcessInstaller1.BeforeInstall += new System.Configuration.Install.InstallEventHandler(this.serviceProcessInstaller1_BeforeInstall);

ProjectInstaller.csハンドラー関数を作成する自動プロセス中に、クラス定義がから変更されたと思います

public class ProjectInstaller : System.Configuration.Install.Installer

partial class ProjectInstaller : System.Configuration.Install.Installer

publicキーワードを。に置き換えますpartial。だから、それを修正するためにそれはしなければなりません

public partial class ProjectInstaller : System.Configuration.Install.Installer

Visual Studio2013Communityエディションを使用しています。

于 2016-07-28T12:18:07.920 に答える
2

VS2010および.NET4.0以降でのステルス変更

RunInstallerAttribute.Yes属性を持つパブリックインストーラーが見つかりませんでした

.NETにはエイリアスの変更またはコンパイラのクリーンアップがあり、特定の場合にこの小さな調整が明らかになる可能性があります。

次のコードがある場合…

RunInstaller(true)   // old alias  

あなたはそれを更新する必要があるかもしれません

RunInstallerAttribute(true)  // new property spelling

これは、コンパイル時または実行時に内部で変更されたエイリアスのようなものであり、このエラー動作が発生します。RunInstallerAttribute(true)に対する上記の明示的な変更により、すべてのマシンのすべてのインストールシナリオで修正されました。

プロジェクトまたはサービスインストーラーを追加した後、「古い」RunInstaller(true)を確認し、新しいRunInstallerAttribute(true)に変更します。

于 2017-01-22T18:02:23.830 に答える
1

私が遭遇したさらに別の落とし穴:インストーラー派生クラス(通常ProjectInstaller)が名前空間階層の最上位にあることを確認し、別のパブリッククラス内でパブリッククラスを使用しようとしましたが、これは同じ古いエラーになります:

RunInstallerAttribute.Yes属性を持つパブリックインストーラーが見つかりませんでした

于 2019-03-26T14:09:32.257 に答える