create MSI for windows service in visual studio 2012 - c#

I have created a windows service in visual studio 2012. I can install the service using installutil, but I need to distribute the service to a client.
How can I build a MSI? There are wwalk throughs in vs2008, but they don't seem to apply to 2012, as 2012 has install shield limited edition and I cannot find Custom Actions anywhere..

Do you have to distribute an MSI?
If all you want is to install the service then the application itself should do it. Use a ServiceInstaller. Add a main argumnet so when you run app.exe /install it isntalls the service (and perhaps /uninstall removes it).
The following topic explains the details: How to: Add Installers to Your Service Application. The ServiceInstaller has code example.
You should use an MSI if you have more complex requirements, if you want your app to appear in the Control Panel/Add-Remove programs, if you want to add 'Repair' installs, if your installation needs to provide options (CLI or UX).

Related

MSI installer for .Net 5 background service

I have a .Net 5 console application that I am trying to run as a Windows service. I have followed all of the articles online on how to do this and have it completed successfully (ie: using BackgroundService). The question is, I want to have an MSI installer to deploy this and all of the articles I have read about creating a service in .Net 5 instruct me to install the service manually using a command prompt or power shell and issuing the "sc" command.
Back before .Net 5, I could use the built in Visual Studio Installer extension and simply create an MSI that would deploy and install my service. I can't seem to make that work for .Net 5.
Is it still possible to use the built in Installer extension to deploy and install my .Net 5 BackgroundService?
Thanks!
Installing Services: There are many ways to install services, you should use an MSI package and the built-in mechanisms there to install and start the service and stop and update it during upgrades.
Various ways to install services (with links to samples on how to install services using MSI).
Learning WiX: Please see the WiX section here - the links should get you started. Direct link to the main WiX link list.
Links:
Windows Services Frequently Asked Questions (FAQ)
Installation package created with WIX Toolset does not remove program folder + files on uninstallation
How to install a system service without permission errors

How to add version info to Windows Service installed via Sc.exe tool?

When you install Windows Service via the wizard (using .msi file), Windows will add a record in Add or remove programs with a version number, that you can set in properties of the Wizard project.
You can also install Windows Service, using Sc.exe tool.
My question is, how to install windows service via Sc.exe tool and still have a record in Add or remove programs with a version. So I know what version of Windows Service is running. Ideal scenario would be to include the version in the code. So that Sc.exe will call MyService.exe without any parameters.
Thanks for help,

Adding windows service to a GUI-Windows application project

I have a GUI based windows application which is an .exe application(TestServer.exe )application. Now I need to add a windows service to this project solution.
So the solution would then build two executables. The first is the one it is currently building using the UserApplication; MyTestServer.exe
The second would be the new Windows Service; MyTestservice.exe.
Both would share the MyTestServerLibrary and our 3rd party dlls.
How can i do that in C# - Visual studio 2010?
As #nvoigt said, you simply add another project to your solution. If you'll right-click on your solution in the Solution Explorer window, select the Add|New Project... menu option. In the resulting dialog, select the Windows Service project type, give it a name, and press OK. Note that this step assumes you have one of the paid versions of Visual Studio 2010. My recollection is that the Windows Service project type is not delivered with the Express version.
From there, you simply build out your Windows service project just like you would any other project. If you've never done this before, I've got a set of instructions for how to do this here. The instructions target Visual Studio 2008 (I really need to update it...), but they are practically identical for Visual Studio 2010.
At this point, when you build your project, you'll get your TestServer.exe, any other C# assemblies that are part of your solution, and the newly-added Windows service executable. By default, running the Windows service directly from the Visual Studio debugger won't work for two reasons. First, your solution probably has TestServer.exe marked as the startup project, which simply means that when you press F5 to start debugging, the TestServer.exe will be run. But even if you change the startup project to be the new Windows service, it still won't work because services don't start the way normal Windows applications do. To get around this, you can look at the instructions here for how to have your Windows service operate in an "interactive" mode, which will let you debug it like any other application. For my purposes, though, I prefer to debug my Windows service when it's actually running as a Windows service. To do this, just put a call to System.Diagnostics.Debugger.Launch() in the constructor for your Windows service. Providing you are an administrator on your system, this will give you the opportunity to jump into a debug session when you start the service from the Services console.
This leads directly to the point of installing the service. To actually run a Windows service, it has to be installed on the system. For .NET-based Windows services, you can use the Microsoft-provided InstallUtil.exe to do this. If you open the Visual Studio command prompt from the Start menu, it's available in the directory path. I prefer the solution that Marc Gravell suggested to have the Windows service install/uninstall itself. I've got a set of instructions for how to do that here.
That should get you started. There are many good answers regarding Windows services on SO, so if you get stuck, be sure to search for it on this site. HTH.

Having Dependency on a thirdparty application in a Windows Application

I have a windows application which lets say Depends on X third-party application which i have its installer file.
i wanna do this:
Deploy my application in a way that it would check if the application is installed other wise use the included installation file to install it,
How can i gain this using Visual Studio Installer Project?
You can select prerequisites for the default installer, too:
http://msdn.microsoft.com/en-us/library/ms165429(v=vs.80).aspx
That should do the trick.

Windows Service not showing up in Services

I created a Windows Service and a setup project.
When I installed the service using the setup installer it is properly installed on the system.
But I didn't see my service in the Services window. I gave all the right permissions, I tried to delete the setup and recreated the new setup still it didn't work.
I tried manually installing using Install Util.exe using the following command
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe C:\myproject\project1\bin\project1.exe
Still it didn't install properly... My system is Windows7 64 bit and VS2010
Is this because of 64 bit system?
You need to add an installer class to your project. Once you have the installer class added you need to add a serviceInstaller and a serviceProcessInstaller to the installer class. You then use these to give your service a display name, install name, etc. I'm surprised the installutil.exe worked without this stuff already setup.

Categories