Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why 'dotnet new webapi' command is producing different folders for me

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It seems to be a recent .NET 8 change resulting in the Minimal APIs used by default.

From the docs for dotnet new templates: webapi (with fixed typo – 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.

So add -controllers/--use-controllers option to the command to get controllers:

dotnet new webapi -n API --use-controllers

Or

dotnet new webapi -n API -controllers
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading