无法访问.net标准中的httpcontext扩展方法 [英] Can't access httpcontext extension methods in .net standard
问题描述
我有一个.NET标准库,我想在其中编写.NET Core中间件.
I have this .NET Standard library where I want to write a .NET Core middleware.
我想在里面做
Endpoint endpoint = httpContext.GetEndpoint();
无法解析 GetEndpoint()
扩展方法.
我引用了 Microsoft.AspNetCore.Http
,并且我同时拥有 Microsoft.AspNetCore.Http.Abstractions
和 Microsoft.AspNetCore.Mvc.Core
包已添加到项目中.
I have referenced Microsoft.AspNetCore.Http
and I have both Microsoft.AspNetCore.Http.Abstractions
and Microsoft.AspNetCore.Mvc.Core
packages added to the project.
是否有解决方案,我是否缺少某些东西?
Is there a solution to this, am I missing something?
推荐答案
我假设您正在为ASP.NET Core 3.1编写中间件,因为其中包含了"asp.net-core-3.1"标记.
I assume you're writing a middleware for ASP.NET Core 3.1 since you included the "asp.net-core-3.1" tag.
要使用该扩展名,您需要定位 netcoreapp3.*
而不是 netstandard2.*
:
To use that extension, you need to target netcoreapp3.*
instead of netstandard2.*
:
<TargetFramework>netcoreapp3.1</TargetFramework>
(您可以在您还需要:
- 使用
Microsoft.NET.Sdk.Web
MSBuild SDK:
- use the
Microsoft.NET.Sdk.Web
MSBuild SDK:
<Project Sdk="Microsoft.NET.Sdk.Web">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
参考: 查看全文