小编Jam*_*urt的帖子

ASP.NET Core 6 应用程序无法找到 UseWindowsService

我的目标是以最简单的方式将 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”类型的接收器

我在这里缺少什么?

c# asp.net-core .net-6.0

10
推荐指数
2
解决办法
1万
查看次数

System.PlatformNotSupportedException:“此平台不支持 Windows 主要功能。”

我们正在调用一个 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

.net .net-core .net-standard

6
推荐指数
1
解决办法
6126
查看次数

标签 统计

.net ×1

.net-6.0 ×1

.net-core ×1

.net-standard ×1

asp.net-core ×1

c# ×1