我的目標是以最簡單的方式將 ASP.NET Core 6 應用程式作為 Windows 服務運行,我理解為使用下面顯示的代碼。
我已經包括了這兩行(盡管只需要頂部):
using Microsoft.AspNetCore.Hosting.WindowsServices;
using Microsoft.Extensions.Hosting.WindowsServices;
并安裝了nuget包:
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="6.0.0" />
.UseWindowsService()但是此代碼在使用時無法決議IWebHostBuilder:
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseConfiguration(Configuration)
.ConfigureServices(ConfigureServices)
.UseUrls(Configuration.GetBindHostUrl())
.UseStartup<Startup>()
.UseWindowsService(); // not found
我得到的錯誤是:
“IWebHostBuilder”不包含“UseWindowsService”的定義,并且最佳擴展方法多載“WindowsServiceLifetimeHostBuilderExtensions.UseWindowsService(IHostBuilder)”需要“IHostBuilder”型別的接收器
我在這里想念什么?
uj5u.com熱心網友回復:
您可以嘗試使用更通用的IHostBuilder而不是使用 WebHost :
var host = Host.CreateDefaultBuilder(args)
.UseWindowsService()
.UseSystemd()
.ConfigureWebHostDefaults(webbuilder =>
{
//Configure here your WebHost. For example Startup;
webbuilder.UseStartup<Startup>();
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/435587.html
