我已经使用.Net Core
worker service
实现了windows service
。从命令提示符安装服务时,出现错误
C:WindowsMicrosoft.NETFramework64v4.0.30319>InstallUtil.exe D:LCWindowServiceL3WorkerService.exe
Microsoft (R) .NET Framework Installation utility Version 4.8.3752.0
Copyright (C) Microsoft Corporation. All rights reserved.
Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly
'file:///D:LCWindowServiceL3WorkerService.exe' or one of its dependencies.
The module was expected to contain an assembly manifest..
我已经尝试了这两种路径
C:WindowsMicrosoft.NETFramework64v4.0.30319>InstallUtil.exe D:LCWindowServiceL3WorkerService.exe
C:WindowsMicrosoft.NETFrameworkv4.0.30319>InstallUtil.exe D:LCWindowServiceL3WorkerService.exe
这是我的项目信息
- 平台目标 - x86
- 输出类型 - 视窗应用程序
- 目标框架 - .NET Core 3.1
如何解决此问题?
要安装服务需要按照以下步骤操作
以管理员身份打开cmd
并切换到项目的输出/发布目录。然后键入
sc create TestService BinPath=D:LCWindowService/TestService.exe
您将收到消息[SC] CreateService SUCCESS
。其他命令也可用,包括start
服务
sc start TestService
sc stop TestService
sc delete TestService
注意:在 .Net Core 服务中,避免使用InstallUtil.exe
。