Add simpler way to get the "old style" console templates
See original GitHub issueIf I don’t want to use the new console style projects with generated top-level statements , since I might feel it becomes the odd-one-out file in a project otherwise consisting of “full” classes, I have to do so in a very round about way, as documented here: https://docs.microsoft.com/en-us/dotnet/core/tutorials/top-level-templates#use-the-old-program-style
The problem with this approach (apart from being very unintuitive) is that it doesn’t work from within VS2022 (sure I could pick 5 then manually change it after, but if I don’t have the 5 SDK installed that leads to more confusing errors on project creation).
Instead I think it would have been cleaner if there was a boolean I could set that the VS IDE also allows me to uncheck to disable the use of top level statements . It would have been cleaner to have something like
dotnet new console --useTopLevelStatements false
and in VS this would translate to a checkbox I can uncheck.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:126
- Comments:18 (2 by maintainers)
Top GitHub Comments
I took the existing console template and tweaked it slightly. I was surprised how little I needed to do, because switching it on and off was already there. So here’s the experience I got in VS with that (notice the extra checkbox): Most of the other features that @KathleenDollard was asking about are also parameters already, so would be easy to expose the same way.
Uncheck it, and you get this:
If you want to try this for yourself, here’s the template package: dotMorten.Console.ProjectTemplates.1.0.1.zip
To install it:
dotnet new --install dotMorten.Console.ProjectTemplates --nuget-source [path to folder with above nuget]
Then open VS2022 and you’ll get this experience. From commandline use:dotnet new console2 --topLevelProgram=false
You can uninstall with
dotnet new --uninstall dotMorten.Console.ProjectTemplates
@KathleenDollard I don’t use the TopLevelStatements because some of the refactorings are not available in it. Take for example the
Introduce local
.Explaining what a class Program and a static method Main is doing isn’t that hard. It also gives me the opportunity to explain readonly fields and access modifiers. Maybe it is just me. But I like the old way just better. So no I’m not considering switching to the new style.