C# 将exe作为服务安装时,如何使用位于单独DLL中的System.Configuration.Install.Installer?

C# 将exe作为服务安装时,如何使用位于单独DLL中的System.Configuration.Install.Installer?,c#,dll,windows-services,C#,Dll,Windows Services,我创建了一个DLL,其中包含一个helper类和安装程序,用于使用命令行参数将exe安装为Windows服务。我从另一个控制台应用程序项目的main方法中调用这个helper方法,该项目只包含一个实现了ServiceBase的类 用法如下: //In console application project static int Main(string[] args) { return new ServiceInstallHelper<MyServiceType>("Servi

我创建了一个DLL,其中包含一个helper类和
安装程序
,用于使用命令行参数将exe安装为Windows服务。我从另一个控制台应用程序项目的main方法中调用这个helper方法,该项目只包含一个实现了
ServiceBase
的类

用法如下:

//In console application project
static int Main(string[] args)
{
    return new ServiceInstallHelper<MyServiceType>("ServiceName").Run(args);
}
将exe作为服务安装

问题是,当我尝试从控制台应用程序运行此代码时,由于安装程序类位于DLL中,而不是exe程序集中,因此程序集中没有安装程序

我可以通过在控制台应用程序项目中添加一个类来修复此问题,该类继承自DLL中的安装程序:

[RunInstaller(true)]
public class Installer : ProjectInstaller
{
}
但我正在寻找一种方法,使这项工作没有这个额外的类


问题归结为这样一个事实:
ManagedInstallerClass.InstallHelper
的参数应该是作为服务安装的exe程序集,但它似乎也希望
System.Configuration.install.Installer
存在于同一程序集中,而我的
安装程序
存在于不同的程序集中。

您不能只使用
typeof(SomethingInTheLibrary.assembly.Location
?可能是
typeof(ProjectInstaller).Assembly.Location
?(而不是
Assembly.GetEntryAssembly().Location
,它是exe)@marcGravel,但它认为我试图将我的DLL作为服务安装,这不起作用。@mclaassen,你解决了这个问题吗?我最近遇到了同样的问题(将我的
安装程序
类移动到公共dll以保持代码一致,请参阅)。您是否找到了此问题的解决方案?@Ofiris看到您似乎也遇到了此问题,您是否找到了解决方案?(请参阅我上面的评论)。
[RunInstaller(true)]
public class Installer : ProjectInstaller
{
}