我有 .NET 6 Web API,并希望作为 Windows 服务托管在我自己的虚拟服务器上。我读了很多问题和答案并应用了它们,但是在启动应用程序时仍然出现错误(错误1053:服务没有及时响应启动或控制请求)而且我找不到详细的当我查看事件日志时出现错误描述。
我正在使用 Microsoft.Extensions.Hosting.WindowsServices 包,Program.cs 如下
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
Args = args,
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
});
builder.Host.UseWindowsService();
var connectionString = builder.Configuration.GetConnectionString("MongoDB");
...
我正在 MAC 上开发,因此使用以下命令发布我的代码
dotnet publish --runtime win7-x64 --self-contained --configuration Release
我正在像这样创建我的Windows服务
sc create "MySvc" binPath= "C:\Users\Administrator\Desktop\test\MySvc.exe"
我哪里做错了或者如何找到错误?
你解决了吗?我也有同样的问题
致敬