当我在Visual Studio2010中创建一个新的Windows service时,我收到一条消息,指出要使用InstallUtil和net start来运行该服务。
我尝试了以下步骤:
TestService
步骤4的输出
运行事务处理安装的
。
开始安装的安装阶段。
查看C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\TestService\obj\x86\Debug\TestService.exe程序集进度的日志文件内容。
该文件位于C:\Users\myusername\Documents\Visual Studio2010\Projects\Tes tService\TestService\obj\x86\Debug\TestService.InstallLog.
安装程序集C:\Users\myusername\Documents\Visual Studio2010\Projects\TestS ervice\TestService\obj\x86\Debug\TestService.exe'.
受影响的参数包括:
logtoconsole =
日志文件= C:\Users\myusername\Documents\Visual Studio2010\Projects\TestService\T estService\obj\x86\Debug\TestService.InstallLog
汇编路径= C:\Users\myusername\Documents\Visual Studio2010\Projects\TestServ ice\TestService\obj\x86\Debug\TestService.exe
在C:\Users\myusername\Documents\Visual Studio2010\Projects\TestService\TestSe rvice\obj\x86\Debug\TestService.exe程序集中找不到具有RunInstallerAttribute.Yes属性的公共安装程序。
安装阶段已成功完成,提交阶段正在开始。
查看C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\TestService\obj\x86\Debug\TestService.exe程序集进度的日志文件内容。
该文件位于C:\Users\myusername\Documents\Visual Studio2010\Projects\Tes tService\TestService\obj\x86\Debug\TestService.InstallLog.
提交程序集'C:\Users\myusername\Documents\Visual Studio2010\Projects\TestS ervice\TestService\obj\x86\Debug\TestService.exe'.
受影响的参数包括:
logtoconsole =
日志文件= C:\Users\myusername\Documents\Visual Studio2010\Projects\TestService\T estService\obj\x86\Debug\TestService.InstallLog
汇编路径= C:\Users\myusername\Documents\Visual Studio2010\Projects\TestServ ice\TestService\obj\x86\Debug\TestService.exe
在C:\Users\myusername\Documents\Visual Studio2010\Projects\TestService\TestSe rvice\obj\x86\Debug\TestService.exe程序集中找不到具有RunInstallerAttribute.Yes属性的公共安装程序。
删除InstallState文件,因为没有安装程序。
提交阶段已成功完成。
事务处理的安装已完成。
步骤5的输出
服务名称无效。
键入NET HELPMSG 2185可获得更多帮助。
发布于 2011-10-28 04:45:56
您需要在设计器中打开Service.cs文件,右键单击它,然后选择菜单选项“添加安装程序”。
它不会开箱即装...首先需要创建installer类。
关于服务安装程序的一些参考:
How to: Add Installers to Your Service Application
相当古老..。但这就是我要说的:
Windows Services in C#: Adding the Installer (part 3)
通过这样做,将自动创建一个ProjectInstaller.cs
。然后,您可以双击它,进入设计器,并配置组件:
serviceInstaller1
具有服务本身的属性: important.serviceProcessInstaller1
具有以下重要属性:Description
、DisplayName
、ServiceName
和StartType
。Account
是运行服务的帐户。例如:
this.serviceProcessInstaller1.Account = ServiceAccount.LocalSystem;
发布于 2011-10-28 04:45:19
查看:
在C:\Users\myusername\Documents\Visual Studio2010\Projects\TestService\TestSe rvice\obj\x86\Debug\TestService.exe程序集中找不到具有RunInstallerAttribute.Yes属性的公共安装程序。
看起来您的代码中可能没有安装程序类。这是一个继承自Installer
的类,它将告诉installutil
如何将可执行文件作为服务安装。
附注:我在这里有我自己的小的自安装/可调试的Windows Service模板,您可以从其中复制代码或使用:Debuggable, Self-Installing Windows Service
发布于 2016-11-04 03:48:48
这里有一种替代的方法来制作安装程序并摆脱那个错误消息。而且,VS2015 express似乎没有“添加安装程序”菜单项。
您只需创建一个类,添加以下代码并添加引用System.Configuration.Install.dll即可。
using System.Configuration.Install;
using System.ServiceProcess;
using System.ComponentModel;
namespace SAS
{
[RunInstaller(true)]
public class MyProjectInstaller : Installer
{
private ServiceInstaller serviceInstaller1;
private ServiceProcessInstaller processInstaller;
public MyProjectInstaller()
{
// Instantiate installer for process and service.
processInstaller = new ServiceProcessInstaller();
serviceInstaller1 = new ServiceInstaller();
// The service runs under the system account.
processInstaller.Account = ServiceAccount.LocalSystem;
// The service is started manually.
serviceInstaller1.StartType = ServiceStartMode.Manual;
// ServiceName must equal those on ServiceBase derived classes.
serviceInstaller1.ServiceName = "SAS Service";
// Add installer to collection. Order is not important if more than one service.
Installers.Add(serviceInstaller1);
Installers.Add(processInstaller);
}
}
}
https://stackoverflow.com/questions/7922105
复制相似问题