var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddControllersWithViews(ops =>
{
//全局异常过滤器,注册
ops.Filters.Add<ExceptionFilter>();
})
// Views视图文件输出到发布目录,视图文件启用运行时编译
.AddRazorRuntimeCompilation()
//接口返回数据json格式
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
});
项目.csproj修改,<PropertyGroup>
里面添加新配置 ,增加如下两个
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
<RazorCompileOnBuild>false</RazorCompileOnBuild>
完整示例:
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<!--输出Views文件-->
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
<RazorCompileOnBuild>false</RazorCompileOnBuild>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>