In Solution Explorer, access Design view for the service for which you want to add an installation component. Click the background of the designer to select the service itself, rather than any of its contents. With the designer in focus, right-click, and then click Add Installer.
In Visual Studio, choose Attach to Process from the Debug menu. The Processes dialog box appears. Click Show system processes. In the Available Processes section, click the process for your service, and then click Attach.
You need to open the Service.cs file in the designer, right click it and choose the menu-option "Add Installer".
It won't install right out of the box... you need to create the installer class first.
Some reference on service installer:
How to: Add Installers to Your Service Application
Quite old... but this is what I am talking about:
Windows Services in C#: Adding the Installer (part 3)
By doing this, a ProjectInstaller.cs
will be automaticaly created. Then you can double click this, enter the designer, and configure the components:
serviceInstaller1
has the properties of the service itself: Description
, DisplayName
, ServiceName
and StartType
are the most important.
serviceProcessInstaller1
has this important property: Account
that is the account in which the service will run.
For example:
this.serviceProcessInstaller1.Account = ServiceAccount.LocalSystem;
Looking at:
No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\TestSe rvice\obj\x86\Debug\TestService.exe assembly.
It looks like you may not have an installer class in your code. This is a class that inherits from Installer
that will tell installutil
how to install your executable as a service.
P.s. I have my own little self-installing/debuggable Windows Service template here which you can copy code from or use: Debuggable, Self-Installing Windows Service
Here is an alternate way to make the installer and get rid of that error message. Also it seems that VS2015 express does not have the "Add Installer" menu item.
You simply need to create a class and add the below code and add the reference 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);
}
}
}
Two typical problems:
Another possible problem (which I ran into):
Be sure that the ProjectInstaller
class is public
. To be honest, I am not sure how exactly I did it, but I added event handlers to ProjectInstaller.Designer.cs
, like:
this.serviceProcessInstaller1.BeforeInstall += new System.Configuration.Install.InstallEventHandler(this.serviceProcessInstaller1_BeforeInstall);
I guess during the automatical process of creating the handler function in ProjectInstaller.cs
it changed the class definition from
public class ProjectInstaller : System.Configuration.Install.Installer
to
partial class ProjectInstaller : System.Configuration.Install.Installer
replacing the public
keyword with partial
. So, in order to fix it it must be
public partial class ProjectInstaller : System.Configuration.Install.Installer
I use Visual Studio 2013 Community edition.
Stealth Change in VS 2010 and .NET 4.0 and Later
No public installers with the RunInstallerAttribute.Yes attribute could be found
There is an alias change or compiler cleanup in .NET that may reveal this little tweak for your specific case.
If you have the following code …
RunInstaller(true) // old alias
You may need to update it to
RunInstallerAttribute(true) // new property spelling
It is like an alias changed under the covers at compile time or at runtime and you will get this error behavior. The above explicit change to RunInstallerAttribute(true) fixed it in all of our install scenarios on all machines.
After you add project or service installer then check for the “old” RunInstaller(true) and change it to the new RunInstallerAttribute(true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With