1、Minimal API创建项目、配置Swagger、理解Map等

1、Minimal API创建项目、配置Swagger、理解Map等

launchSettings.json,专门配置 V本地启动项目的运行参数,控制:启动方式、端口、环境变量、只在本地开发时生效,发布到服务器完全不会使用这个文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",//使用 dotnet run 方式启动项目
"dotnetRunMessages": true,//控制台输出详细启动日志
"launchUrl": "Swagger", //浏览器打开的默认地址,直接跳接口文档,不用手动输 /swagger
"launchBrowser": true,//自动启动浏览器
"applicationUrl": "https://localhost:7295;http://localhost:5102",
"environmentVariables": { //环境变量
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

快速设置Swagger

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//nuget安装Swashbuckle.AspNetCore

//API站点扫描器
builder.Services.AddEndpointsApiExplorer();
//Swagger生成器
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
//启用中间件
app.UseSwagger();
//启用SwaggerUI中间件
app.UseSwaggerUI();
}

1、Minimal API创建项目、配置Swagger、理解Map等

https://bubuweiying.site/MinimalAPI创建项目配置SwaggerMapGroup/

作者

步步为营

发布于

2026-06-25

更新于

2026-06-25

许可协议