2

最初に言うと、私は通常、InstallUtilコマンドを使用してVisual Studio コマンド プロンプト 2010に Windows サービスをインストールします。

Start Debugging (F5) で Visual Studio から Windows サービスを直接インストールすることはできますか?

Windows サービス プロジェクトの [プロパティ] の [デバッグ] タブで cmd.exe を起動しようとしました。

外部プログラムを起動します: C:\Windows\System32\cmd.exe

コマンド ライン引数: /k "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 (これにより、InstallUtil が cmd のコマンドとして有効になります)

そのcmdで開きます。cmd を実行すると、自動的に実行されるようにしたいと思います。

InstallUtil MyServiceName

(cmd が起動すると、myservice.exe がある Debug フォルダーに既に存在します)

それはどういうわけか可能ですか?

4

1 に答える 1

1

ここに完全な解決策があります。

プロジェクトにインストール コードを追加せずに、デバッグの開始 (F5) 時に Visual Studio から Windows サービスを自動的にインストールします (Windows サービスをまったく登録する必要があるプロジェクト インストーラーを除く)。

Visual Studio 2010 プロジェクトのプロパティ

サービス プロジェクトを右クリックし、プロパティを選択します。デバッグセクションに移動します。これを入力してください:

外部プログラムを開始します: C:\Windows\System32\cmd.exe (cmd.exe へのパス)

コマンド ライン引数: /k "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 & sc delete MyServiceName & InstallUtil MyServiceFileName.exe & Exit (パスを自分のものに変更することを忘れないでください)

MyServiceName is value of ServiceName property of serviceInstaller from ProjectInstaller.cs (generated by VS)

MyServiceFileName is name of compiled *.exe file in your Debug folder. Probably same as name of project.

What that did?

We started command prompt that uses powers of visual studio command prompt (we need InstallUtil), deleted old instance of service if it exists, and install new one (and starts it if it's StartType is Automatic)

If you need...

Debugging

Visual Studio 2010. Go to Debug / Attach to proccess. Mark Show processes from all users and Show processes from all session to be able to see your windows services. Name of the process will be your MyServiceFileName. Processes must be attached manually every time you want to debug them. Ofcourse, service must be started to be visible and debugable.

To create the installers for your service (MSDN)

To see how to create installer for your windows service go to this link:

http://msdn.microsoft.com/en-us/library/zt39148a%28v=vs.100%29.aspx

于 2013-09-06T11:14:01.280 に答える