无法解析我的 .NET 6 class 库中的“AddAuthorization”
Can't resolve `AddAuthorization` in my .NET 6 class library
所以我确定我在这里遗漏了一些非常明显的东西,但我似乎无法确定它。
我有一个 .NET 6 class 库:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
</ItemGroup>
</Project>
我的库中有一个生成器正在尝试注册 AddAuthorization
服务,但由于某种原因它无法解析:
namespace MyLib;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
public class MyLibBuilder
{
public IServiceCollection Services { get; }
public MyLibBuilder(IServiceCollection services)
{
Services = services;
}
public MyLibBuilder MapAuthorizationPolicies()
{
Services.AddAuthorization();
return this;
}
}
我已经:
- 三次检查我安装了
Microsoft.Extensions.DependencyInjection
和 Microsoft.AspNetCore.Authorization
- 重建解决方案
- 卸载并重新加载项目
没有骰子。我确定一旦我离开一天它就会立即点击,但这真的让我很困扰我到底错过了什么?
Note: If I change it to a Microsoft.NET.Sdk.Web
project, it will resolve, but then I need a Main
to run which is moot here since this is just a class lib. Web
has to be doing something else that I'm missing but i'm not seeing it...
根据this,这是一个重大变化。
以下是推荐的解决方案,尽管我确实尝试引用 Policy
仍然没有任何乐趣。
Either add a reference to Microsoft.AspNetCore.Authorization.Policy or use AddAuthorizationCore instead
所以我确定我在这里遗漏了一些非常明显的东西,但我似乎无法确定它。
我有一个 .NET 6 class 库:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
</ItemGroup>
</Project>
我的库中有一个生成器正在尝试注册 AddAuthorization
服务,但由于某种原因它无法解析:
namespace MyLib;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
public class MyLibBuilder
{
public IServiceCollection Services { get; }
public MyLibBuilder(IServiceCollection services)
{
Services = services;
}
public MyLibBuilder MapAuthorizationPolicies()
{
Services.AddAuthorization();
return this;
}
}
我已经:
- 三次检查我安装了
Microsoft.Extensions.DependencyInjection
和Microsoft.AspNetCore.Authorization
- 重建解决方案
- 卸载并重新加载项目
没有骰子。我确定一旦我离开一天它就会立即点击,但这真的让我很困扰我到底错过了什么?
Note: If I change it to a
Microsoft.NET.Sdk.Web
project, it will resolve, but then I need aMain
to run which is moot here since this is just a class lib.Web
has to be doing something else that I'm missing but i'm not seeing it...
根据this,这是一个重大变化。
以下是推荐的解决方案,尽管我确实尝试引用 Policy
仍然没有任何乐趣。
Either add a reference to Microsoft.AspNetCore.Authorization.Policy or use AddAuthorizationCore instead