I would like to create a setup for my windows service. The dlls of my windows service are placed in /Lib/ folder.
I added an installer class to the service. And added a custom action on the setup project.
The problem is that when I try to install the service - it fails with the error: Error 1001. Unable to get installer types in ...
This error happens because the dlls are not in the same directory as the service .exe. I am using probing in the service config and install util doesn't recognize that probing..
I wanted to find a work around for that problem and tryed in many ways to create the service using service controller(sc.exe). Trying to run it as a custom action using cmd.exe. Etc..
This should be a common problem..did anybody find a proper solution for that?
Use an installer program such as Windows Installer 2.0. Windows Installer 2.0 can install, repair, or remove .NET Framework assemblies in the global assembly cache and in private directories. To determine where to deploy your application's assemblies so they can be found by the runtime, see How the Runtime Locates Assemblies.
If you’re developing a Windows Service by using the .NET Framework, you can quickly install your service application by using a command-line utility called InstallUtil.exe. If you’re a developer who wants to release a Windows Service that users can install and uninstall you should use InstallShield.
The .NET Framework 3.5 SP1 offline installer is available on the .NET Framework 3.5 SP1 Download page and is available for Windows versions prior to Windows 10. You may see the following configuration dialog if you try to run an app that requires the .NET Framework 3.5.
Get inside the newly formed folder and run the dotnet publish command. Do dotnet publish -r win-x64 -c Release to make a windows installer on publishing. Image by Author.
I've had the same problem, and none of the options suggested in this post or MSDN helped. I figured another solution:
By using Reflector on InstallUtil.exe, I discovered that InstallUtil is merely a thin wrapper for calling System.Configuration.Install.ManagedInstallerClass.InstallHelper(args)
inside a try/catch block (it also sets the current thread's UI culture and displays the copyright). ManagedInstallerClass.InstallHelper
itself resides in the System.Configuration.Install.dll assembly, accessible to everyone.
Thus, I simply modified the Program.Main
method of my service to allow installation. See the quick-and-dirty code below:
static class Program
{
static void Main(string[] args)
{
if (args != null && args.Any(arg => arg == "/i" || arg == "/u"))
{
// Install or Uninstall the service (mimic InstallUtil.exe)
System.Configuration.Install.ManagedInstallerClass.InstallHelper(args);
}
else
{
// Run the service
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[]
{
new MyService()
};
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
}
}
You can do the same, or create your own version of InstallUtil.
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