Exe 安装抛出错误该模块应包含程序集清单 .Net Core

Exe installation throwing error The module was expected to contain an assembly manifest .Net Core

我已经使用 .Net Core worker service 实现了 windows service。从命令提示符安装服务时,出现错误

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe D:\LC\WindowService\L3WorkerService.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:\LC\WindowService\L3WorkerService.exe' or one of its dependencies. 
The module was expected to contain an assembly manifest..

这两条路我都试过了

C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe D:\LC\WindowService\L3WorkerService.exe
C:\Windows\Microsoft.NET\Framework\v4.0.30319>InstallUtil.exe D:\LC\WindowService\L3WorkerService.exe

这是我的项目信息

我该如何解决这个问题?

安装服务需要按照以下步骤进行

以管理员身份打开 cmd 并切换到项目的 output/publish 目录。然后输入

sc create TestService BinPath=D:\LC\WindowService/TestService.exe

您将收到消息 [SC] CreateService SUCCESS。还可以使用其他命令,包括 start service

sc start TestService
sc stop TestService
sc delete TestService

注意:在 .Net Core 服务中避免使用 InstallUtil.exe