简体   繁体   中英

Installing .net windows service with lib folder

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?

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.

You should bind to the AppDomain.AssemblyResolve event and do your custom loading in the event handler.

A sample can be found in the first answer to this SO question .

在您的配置中,您可以添加探测路径 - 它是运行时在哪里查找程序集的提示http://msdn.microsoft.com/en-us/library/823z9h8w%28v=vs.80%29.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM