所以。我使用模型 ASP.NET Core with Angular 使用 Visual Studio Pro 2019 (v16.11.9) 创建了一个全新的项目。我将身份验证选项设置为个人用户帐户。
我得到了一个使用 Angular 8、ASP.NET Core 3.1(没有深究为什么这些版本,只是接受事实)、Entity Framework 和 Identity 的工作脚手架项目,这正是我想要的除了框架版本。我想使用最新版本,因此 Angular 13 和 ASP.NET Core 6.0。
所以我开始逐个版本升级我的 Angular 版本,检查每一步应用程序是否仍然有效。到达 Angular 13,没有发现问题,身份验证工作正常。
然后,我按照非常复杂(此处具有讽刺意味)的 Microsoft 教程来更新您的 .NET Core 版本:从 ASP.NET Core 3.1 迁移到 6.0 并更新 .csproj。 boom,当我尝试访问应用程序受身份验证保护的部分时,出现以下错误:
InvalidOperationException: The default Identity UI layout requires a partial view '_LoginPartial' usually located at '/Pages/_LoginPartial' or at '/Views/Shared/_LoginPartial' to work. Based on your configuration we have looked at it in the following locations: /Areas/Identity/Pages/Account/_LoginPartial.cshtml /Areas/Identity/Pages/_LoginPartial.cshtml /Areas/Identity/Pages/Shared/_LoginPartial.cshtml /Areas/Identity/Views/Shared/_LoginPartial.cshtml /Pages/Shared/_LoginPartial.cshtml /Views/Shared/_LoginPartial.cshtml.
<PropertyGroup>
<UseRazorSourceGenerator>false</UseRazorSourceGenerator>
</PropertyGroup>
添加此内容的原因是我在构建过程中收到以下消息: 1>CSC:警告 CS8785:生成器“RazorSourceGenerator”无法生成源。它不会对输出产生影响,因此可能会出现编译错误。异常的类型为“NullReferenceException”,消息为“对象引用未设置为对象的实例。”
从另一个来源我发现,添加此属性组可以提供更详细的信息,但它解决了未编译的视图:
https://developercommunity.visualstudio.com/t/vs-2022-mvc-core-不生成预编译-vie/1577269#T-N1578977https://github.com/dotnet/aspnetcore/issues/41277将项目从 .NET 7 迁移到 .NET 8 时,我也遇到了完全相同的问题。当我尝试清理项目时,收到一条错误消息,提示我当前的 Visual Studio 版本不支持 .NET 8 - 但这并不明显。更新到最新后就不再报错了。