我正在尝试安装 Windows 服务。
运行 c:\windows\microsoft.net\Framework64\v4.0.30319\InstallUtil.exe c:\foo\MyAssembly.exe
我收到一条好消息,表明所有阶段(安装、提交)都已成功完成。
(我没有收到输入服务凭证的提示)
之后我在服务控制台中看不到该服务。安装日志中没有任何用处。
该解决方案是在 64 位机器上构建的,我正在尝试在 64 位机器上安装该服务。但是,我没有将 64 位视为解决方案属性中的一个选项。我确实手动编辑了所有 csproj 文件,为 [platform] 节点选择“x64”..
我可以毫无问题地在 visual studio 外运行该服务。
安装程序.cs
[RunInstaller(true)]
public partial class Installer : System.Configuration.Install.Installer
{
public Installer() {
InitializeComponent();
}
}
这是 visual studio 提供的默认安装程序。
最佳答案
您需要将一些 Installer 对象添加到 Installers 集合中。示例 here是安装 Windows 服务所需的。有点像
[RunInstaller(true)]
public class Installer : System.Configuration.Install.Installer
{
private ServiceInstaller serviceInstaller;
private ServiceProcessInstaller processInstaller;
public Installer()
{
// Instantiate installers for process and services.
processInstaller = new ServiceProcessInstaller();
serviceInstaller = new ServiceInstaller();
// The services run under the system account.
processInstaller.Account = ServiceAccount.LocalSystem;
// The services are started manually.
serviceInstaller.StartType = ServiceStartMode.Manual;
// ServiceName must equal those on ServiceBase derived classes.
serviceInstaller.ServiceName = "Hello-World Service 1";
// Add installers to collection. Order is not important.
Installers.Add(serviceInstaller);
Installers.Add(processInstaller);
}
}
关于c# - installutil 成功完成但未安装服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12362455/