netcor6.0 swargger 生成带注释的api 电脑版发表于:2022/11/7 14:13 ## 目录 * [api带有中文注释和字段解释](#api带有中文注释和字段解释) * [program](#program) * [项目配置](#项目配置) # api带有中文注释和字段解释 ## program ```c# builder.Services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "web API", Description = "这个是个人服务类", }); //增加当前项目集的xml注释 var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); //增加home项目集的xml注释 var apiFilename = $"{typeof(HomeControlller).Assembly.GetName().Name}.xml"; options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, apiFilename)); }); ``` ## 项目配置 > 双击项目两下 把写着api的项目配置上 ```c# <PropertyGroup> //生成文档文件 <GenerateDocumentationFile>true</GenerateDocumentationFile> </PropertyGroup> ```