.net.net-6.0dotnet-cli

Create a Web API without top-level statements


I am using dotnet cli to create an ASP.NET Core Web API

dotnet new webapi --output WebAPI;

Is it possible to create it but without top-level statements?


Solution

  • You can use --use-program-main switch (or --use-program-main true) for the dotnet new command:

    dotnet new webapi --output WebAPI --use-program-main
    

    Note that this will just generate Main method. The minimal hosting model will still be used (so no Startup).