这似乎是.NET8最近的一个更改,导致默认使用Minimal APIs.
来自dotnet new templates: webapi的文档(带有固定的打字错误PR @github):
-minimal
|--use-minimal-apis
Create a project that uses the ASP.NET Core minimal API. Default is false, but this option is overridden by --controllers
. Since the default for --controllers
is false
, entering dotnet new webapi
without specifying either option creates a minimal API project.
-controllers
, --use-controllers
Whether to use controllers instead of minimal APIs. If both this option and -minimal
are specified, this option overrides the value specified by -minimal
. Default is false
. Available since .NET 8 SDK.
因此,在命令中添加-controllers
/--use-controllers
选项以获取控制器:
dotnet new webapi -n API --use-controllers
或
dotnet new webapi -n API -controllers