我正在尝试构建可自行安装的Windows服务。我有一个像这样定义的安装程序类:
[RunInstaller(true)]
public class MyServiceInstaller : Installer
{
public MyServiceInstaller()
{
var serviceProcessInstaller = new ServiceProcessInstaller
{
Account = ServiceAccount.LocalSystem
};
var serviceInstaller = new ServiceInstaller
{
DisplayName = "MyService",
StartType = ServiceStartMode.Automatic,
ServiceName = "MyService",
Description = "My Service Description"
};
Installers.Add(serviceProcessInstaller);
Installers.Add(serviceInstaller);
}
}
这是我用来执行安装的代码:
public void Install()
{
using (var assemblyInstaller = new AssemblyInstaller(
typeof(MyService).Assembly,
null) {
UseNewContext = true
})
{
var state = new Hashtable();
try
{
assemblyInstaller.Install(state);
assemblyInstaller.Commit(state);
}
catch
{
try
{
assemblyInstaller.Rollback(state);
}
catch {}
throw;
}
}
}
当我从ASP.NET应用程序触发安装时,包含我的Windows服务的程序集安装在以下位置:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\xxxxxxx\25c14c59\a945a1e6\assembly\dl3\abf52138\74461ad8_8d5bce01\MyService.EXE
问题是,这个程序集是唯一安装的文件。
问题: