Bring back the option to use old templates (non-top level statements style) (changed in .NET Preview 7)
See original GitHub issueWhile 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:
- Created 2 years ago
- Reactions:42
- Comments:16 (10 by maintainers)
Top GitHub Comments
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:
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 inConfigure...
”, 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.
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 declaredProgram
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
andStartup
class by selecting “.NET 5.0” in the new project dialog in Visual Studio, or passing-f net5.0
to thedotnet new
comment at the command line, and then retarget the project to .NET 6 once it’s created.