I'm a beginner in dotnet technology and I'm following a tutorial but upon using dotnet new webapi -n API it produces the API folder with the properties, obj and bin folder as in the picture below but it doesn't have Controllers folder like in the tutorial. Can anyone guide me on this ? The project is using .NET 8.0Image1

推荐答案

这似乎是.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

.net相关问答推荐

创建仅包含msBuild.Target的Nuget包

是否可以将 SandCastle 创建的两个页面合并到一个主页中?

无法加载文件或程序集 Microsoft.Extensions.DependencyInjection.Abstractions,版本 = 1.1.0.0

使用 Thread.Abort() 有什么问题

maxRequestLength 的最大值?

将屏幕捕获为位图

为什么 ?: 会导致转换错误,而 if-else 不会?

什么是 project.lock.json?

如何使用 NUnit(或可能使用另一个框架)测试异步方法?

哪个更快:清除集合或实例化新的

.NET 如何判断路径是否是文件而不是目录?

ObservableCollection<> 与 List<>

我不了解应用程序域

.NET 的 String.Normalize 有什么作用?

一个接口是否应该继承另一个接口

使 HashSet 不区分大小写

.NET 委托类型的正确命名约定?

在 IIS 中访问 .svc 文件时出现 HTTP 404

System.Array.CopyTo() 和 System.Array.Clone() 之间的区别

在构建事件命令行中放置注释的正确方法?