【发布时间】:2019-02-20 16:42:04
【问题描述】:
我有一个由两个项目组成的简单解决方案:
- ASP.NET Core 主项目
- Razor 类库
我想在 razor 类库中使用 IdentityRole,所以我在我的 razor 类库项目中以及在编写时下载了 Microsoft.AspNetCore.Identity
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace RazorClassLibrary2.MyFeature.Pages
{
public class Page1Model : PageModel
{
public void OnGet()
{
IdentityRole role;
}
}
}
我收到以下错误:
找不到类型或命名空间名称“IdentityRole”(您是否缺少 using 指令或程序集引用?)
因为我想使用 .Net Core 框架,但 Razor 类库是用创建的
<TargetFramework>netstandard2.0</TargetFramework>
我改成
<TargetFramework>netcoreapp2.2</TargetFramework>
注意:更改 TargetFramework 似乎没问题,请参阅此评论 https://github.com/aspnet/Docs/issues/7816#issuecomment-428193831
认为这种操作可能是问题的原因,我创建了另一个“项目>类库(.Net Core)”,下载了Microsoft.AspNetCore.Identity,并创建了另一个类
using Microsoft.AspNetCore.Identity;
using System;
namespace ClassLibrary1
{
public class Class1
{
IdentityRole role;
}
}
如果我在 ASP.NET Core(主)项目中下载 Microsoft.AspNetCore.Identity 并在主项目的任何类中声明 IdentityRole 类型的变量,则找到该引用。
我哪里错了?
你可以在这里找到一个示例项目https://github.com/Blackleones/identityTest如果你想合作,请随时发送拉取请求。
【问题讨论】:
标签: c# asp.net-core asp.net-identity