First to say, I normally install my windows service in visual studio command prompt 2010 with InstallUtil command.
Is it possible to install my windows service directly from visual studio by Start Debugging (F5)?
I tryed to start cmd.exe in my windows service project Properties, under Debug tab:
Start external program: C:\Windows\System32\cmd.exe
Command line arguments: /k "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 (with this InstallUtil is enabled as command in cmd)
With that cmd will open. I would like that when cmd is run it automaticly executes:
InstallUtil MyServiceName
(when cmd starts it is already in my Debug folder where myservice.exe is)
Is that possible somehow?
Here is complete solution.
What
Installing windows service automatically from Visual Studio when Start Debugging (F5) without adding any installing code to the project (except project installer you need to register windows service at all).
Visual Studio 2010 project properties
Right click your service project and choose properties. Go to Debug section. Input this:
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