需要修改两处代码:
1、用记事本打开项目的csproj文件,增加GenerateDocumentationFile节点。
<PropertyGroup> <TargetFramework>net6.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> <GenerateDocumentationFile>true</GenerateDocumentationFile> </PropertyGroup>
2、修改Program.cs文件,在Build之前增加SwaggerGen代码块。
builder.Services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "API标题", Description = "API描述" }); var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); }); /*配置日志 结束*/ var app = builder.Build();
标签:接口,API,Build,var,Net,Swagger,options From: https://www.cnblogs.com/tudou365/p/17044243.html