我的目标是以最简单的方式将 ASP.NET Core 6 应用程序作为 Windows 服务运行,我理解为使用下面所示的代码。
我已经包含了这两行(尽管只有顶部是必要的):
using Microsoft.AspNetCore.Hosting.WindowsServices;
using Microsoft.Extensions.Hosting.WindowsServices;
Run Code Online (Sandbox Code Playgroud)
并安装 nuget 软件包:
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="6.0.0" />
Run Code Online (Sandbox Code Playgroud)
.UseWindowsService()
但使用以下代码时无法解析IWebHostBuilder
:
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseConfiguration(Configuration)
.ConfigureServices(ConfigureServices)
.UseUrls(Configuration.GetBindHostUrl())
.UseStartup<Startup>()
.UseWindowsService(); // not found
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
“IWebHostBuilder”不包含“UseWindowsService”的定义,并且最佳扩展方法重载“WindowsServiceLifetimeHostBuilderExtensions.UseWindowsService(IHostBuilder)”需要“IHostBuilder”类型的接收器
我在这里缺少什么?
我们正在调用一个 dotnet 标准 dll,它在 WindowsIdentity 上调用 GetCurrent。它在 dotnet 核心应用程序中工作正常,但是一旦将其导入到 dotnet 框架 (4.7.2) 应用程序中,就会出现以下错误:
System.PlatformNotSupportedException: 'Windows Principal functionality is not supported on this platform.'
Run Code Online (Sandbox Code Playgroud)
尽管几个月前在 dotnet/standard github 问题论坛上提出了这个问题,但这个问题仍然存在: https: //github.com/dotnet/standard/issues/1279