[英]Installing .net windows service with lib folder
I would like to create a setup for my windows service. 我想为我的Windows服务创建一个设置。 The dlls of my windows service are placed in /Lib/ folder.
我的Windows服务的dll放在/ Lib /文件夹中。
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 ... 问题是,当我尝试安装该服务时 - 它失败并显示错误:错误1001.无法获取安装程序类型...
This error happens because the dlls are not in the same directory as the service .exe. 发生此错误是因为dll与服务.exe不在同一目录中。 I am using probing in the service config and install util doesn't recognize that probing..
我在服务配置中使用探测并且安装util无法识别探测..
I wanted to find a work around for that problem and tryed in many ways to create the service using service controller(sc.exe). 我想找到解决该问题的方法,并尝试使用服务控制器(sc.exe)以多种方式创建服务。 Trying to run it as a custom action using cmd.exe.
尝试使用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. 我遇到了同样的问题,这篇文章或MSDN中没有提出任何选项。 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). 通过在InstallUtil.exe上使用Reflector,我发现InstallUtil只是一个瘦的包装器,用于在try / catch块中调用
System.Configuration.Install.ManagedInstallerClass.InstallHelper(args)
(它还设置当前线程的UI文化并显示版权)。 ManagedInstallerClass.InstallHelper
itself resides in the System.Configuration.Install.dll assembly, accessible to everyone. ManagedInstallerClass.InstallHelper
本身驻留在System.Configuration.Install.dll程序ManagedInstallerClass.InstallHelper
,每个人都可以访问。 Thus, I simply modified the Program.Main
method of my service to allow installation. 因此,我只是修改了我的服务的
Program.Main
方法以允许安装。 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. 您也可以这样做,或者创建自己的InstallUtil版本。
You should bind to the AppDomain.AssemblyResolve
event and do your custom loading in the event handler. 您应该绑定到
AppDomain.AssemblyResolve
事件并在事件处理程序中执行自定义加载。
A sample can be found in the first answer to this SO question . 可以在此SO问题的第一个答案中找到样本。
在您的配置中,您可以添加探测路径 - 它是运行时在哪里查找程序集的提示http://msdn.microsoft.com/en-us/library/823z9h8w%28v=vs.80%29.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.