Windows 服务安装程序 - 服务名称包含无效字符、为空或太长
Windows Service Installer - Service name contains invalid characters, is empty, or is too long
我一直在关注 this MSDN article 编写 Windows 服务和随附的安装程序。当我尝试添加安装程序项目并右键单击设计视图和 select 'Add Installer' 时,我收到以下消息:
Service name contains invalid characters, is empty, or is too long
我的服务名称设置为"UploadManagerService"。这不包含我知道的任何无效字符,并且低于指定的 80 个字符限制。
我在这里阅读了几篇关于这个问题的文章。 This answer suggests that this is because the service name isn't set in Visual Studio though this is set in my case. I've also tried setting the service name in the app.config 看看是否有什么不同。还有其他我可能会遗漏的东西或解决这个问题的方法吗?
我无法理解名称有什么问题,但我可以通过使用几行代码手动编写安装程序来解决这个问题。
假设您遵循 MSDN article 并在 selecting 'Add Installer' 后遇到同样的问题:
- Select 'ProjectInstaller.cs' 在解决方案资源管理器上并按 F7 / right-click 和 select 'View Code'.
- 如果 class 的构造函数不存在,请添加一个或编辑现有的
构造函数。
添加以下代码:
var process = new ServiceProcessInstaller {Account = ServiceAccount.LocalSystem};
var serviceAdmin = new ServiceInstaller
{
StartType = ServiceStartMode.Manual,
ServiceName = "MyServiceName",
DisplayName = "My Service Display Name"
};
Installers.Add(process);
Installers.Add(serviceAdmin);
InitializeComponent();
在此之后,我继续按照 MSDN 文章中的说明进行操作,并能够使用 InstallUtil.exe 安装该服务。
我仍然none更清楚为什么这行不通,但希望这能帮助其他人解决这个问题。
我会考虑看这个:
Create and Package a Windows Service using IsWiX
您可以通过取消使用 InstallUtil 并使用本机 MSI 功能来真正简化问题。事实上,您会注意到视频只用了 2 分钟,其中一半时间用于创建实际服务。
我收到了这个确切的错误,一切都应该没问题。您快速阅读错误消息,责备它,然后开始检查项目名称、类 的名称以及...等一下:
MSDN tutorial 命名此步骤:
In the Design tab, select Properties from the shortcut menu. From the Properties window, change the ServiceName value to MyNewService.
我只是在构建服务时没有遵循教程,所以请记住伙计们:阅读错误消息并检查它所抱怨的每一个点!
我一直在关注 this MSDN article 编写 Windows 服务和随附的安装程序。当我尝试添加安装程序项目并右键单击设计视图和 select 'Add Installer' 时,我收到以下消息:
Service name contains invalid characters, is empty, or is too long
我的服务名称设置为"UploadManagerService"。这不包含我知道的任何无效字符,并且低于指定的 80 个字符限制。
我在这里阅读了几篇关于这个问题的文章。 This answer suggests that this is because the service name isn't set in Visual Studio though this is set in my case. I've also tried setting the service name in the app.config 看看是否有什么不同。还有其他我可能会遗漏的东西或解决这个问题的方法吗?
我无法理解名称有什么问题,但我可以通过使用几行代码手动编写安装程序来解决这个问题。
假设您遵循 MSDN article 并在 selecting 'Add Installer' 后遇到同样的问题:
- Select 'ProjectInstaller.cs' 在解决方案资源管理器上并按 F7 / right-click 和 select 'View Code'.
- 如果 class 的构造函数不存在,请添加一个或编辑现有的 构造函数。
添加以下代码:
var process = new ServiceProcessInstaller {Account = ServiceAccount.LocalSystem};
var serviceAdmin = new ServiceInstaller
{
StartType = ServiceStartMode.Manual,
ServiceName = "MyServiceName",
DisplayName = "My Service Display Name"
};
Installers.Add(process);
Installers.Add(serviceAdmin);
InitializeComponent();
在此之后,我继续按照 MSDN 文章中的说明进行操作,并能够使用 InstallUtil.exe 安装该服务。
我仍然none更清楚为什么这行不通,但希望这能帮助其他人解决这个问题。
我会考虑看这个:
Create and Package a Windows Service using IsWiX
您可以通过取消使用 InstallUtil 并使用本机 MSI 功能来真正简化问题。事实上,您会注意到视频只用了 2 分钟,其中一半时间用于创建实际服务。
我收到了这个确切的错误,一切都应该没问题。您快速阅读错误消息,责备它,然后开始检查项目名称、类 的名称以及...等一下:
MSDN tutorial 命名此步骤:
In the Design tab, select Properties from the shortcut menu. From the Properties window, change the ServiceName value to MyNewService.
我只是在构建服务时没有遵循教程,所以请记住伙计们:阅读错误消息并检查它所抱怨的每一个点!