csproj 文件中添加下面的配置
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
增加下面2行
<RazorCompileOnBuild>false</RazorCompileOnBuild>
<RazorCompileOnPublish>false</RazorCompileOnPublish>
增加这2行
<UserSecretsId>bf54dea4-71f2-4482-b48a-635d3a3ac3f8</UserSecretsId>
</PropertyGroup>
安装 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation 包版本3.1
编辑Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddRazorPages().AddRazorRuntimeCompilation();
}