question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bring back the option to use old templates (non-top level statements style) (changed in .NET Preview 7)

See original GitHub issue

While I appreciate the benefits of top level statements, especially for beginners that want to start their journey with C#/.NET/ASP.NET Core, many of us create larger Web APIs and applications for which the new templates (top level statements style project architecture) are unsuitable and require manually looking up and writing the old Startup.cs-style boilerplate (looking up as I doubt many of us have it exactly memorised as it was always something that was automatically included in the template). It would be nice if you either made the top-level statement style templates opt-in via something like dotnet new webapi --minimal or dotnet new webapi-simple or if you insist that the top level statement should be the default as it is simpler, then do not completely get rid of the old style templates but make those opt-in e.g. dotnet new webapi-full or dotnet new webapi --full.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:42
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

24reactions
NickCravercommented, Sep 16, 2021

I wanted to add more thoughts on the “why” here after thinking about it a bit. A few of my primary use cases for templates are:

  1. To upgrade from vX to vY, with this complete break it’s a lot less obvious what’s changed or what I should do (e.g. when the move to Endpoint routing happened).
  2. When helping others.

When I’m helping people whether it be through docs or descriptions or examples, I’m telling them “be sure to add X here”, e.g. “In ConfigureServices…, and in Configure...”, that’s an easy explanation. How do you get an instance of a service to use in `Configure? “Just add it to the method signature”. None of that works anymore - none of the documentation we have works for new templates.

Though we’re pitching these as an additive thing or more useful for new users (I can certainly see they might be), replacing the templates creates a lot more friction in both upgrades and all existing instructions and docs. I can add .NET 6 examples to everything (and looks like I’ll have to), but do we want to create that much friction for new users? Any helpful issue that describes a fix has to be adapted at the very least and discussing general changes/problems here is less structured, and therefore harder. All instructions are harder when the landmarks are removed. The language/layout will be a hurdle for some (even most?), and further the lack of structure in this template will be another.

This is pure opinion, but I think the minimal approach here works up to a point. And before that point, they can certainly be argued to be a win. But past that point where you need to do something complex or is too complex to maintain in this way, we’ve added a learning cliff. It is, in many ways, 2 ways of doing something - and for every item that’s different, you need to re-learn it (or keep up with both) over that cliff. Without even the 2 base templates to understand what’s happening in this minimal version or compare it to “the old style”, we’re creating a burden for users.

Please reconsider having both templates available.

22reactions
DamianEdwardscommented, Aug 24, 2021

At this point we aren’t planning to add options to the templates or provide additional templates to enable adding back a Startup class or an explicitly declared Program class. Adding options or template variations adds complexity to the experience that we’d prefer to avoid if possible.

As a workaround, you can create new web projects that include a Program and Startup class by selecting “.NET 5.0” in the new project dialog in Visual Studio, or passing -f net5.0 to the dotnet new comment at the command line, and then retarget the project to .NET 6 once it’s created.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core updates in .NET 8 Preview 7
NET 8 Preview 7 is now available and includes many great new improvements to ASP.NET Core. Here's a summary of what's new in...
Read more >
Disabling .NET 6 features per default
NET 6 console app template generates the new style of top-level statements programs, using .NET 5 doesn't. By creating a .NET 5 project ......
Read more >
VS now includes a "Do not use top-level statements" option ...
This checkbox reverts "top level statements" (ie no Program class). But it still keeps using the asp.net minimal apis just inside of a...
Read more >
ASP.NET Core 6 - how to deal with the missing Startup.cs file
The idea is to remove the "cruft" that was present in every console application or ASP.NET Core application.
Read more >
Implicit Using Statements In .NET 6 - NET Core Tutorials
With Implicit Using statements, your code will have almost invisible using statements declared globally! Let's take a look at this new feature, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found