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.

Add simpler way to get the "old style" console templates

See original GitHub issue

If 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 image

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:closed
  • Created 2 years ago
  • Reactions:126
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

22reactions
dotMortencommented, Oct 9, 2021

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): image 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: image

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

17reactions
sonnemafcommented, Oct 11, 2021

@KathleenDollard I don’t use the TopLevelStatements because some of the refactorings are not available in it. Take for example the Introduce local.

image

image

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# console app template generates top-level statements
Convert the new program style to the older style, with a Program class and a Main method. If you want to use the...
Read more >
How can .Net 6.0 console app template create the old ...
There is a way to get back to the old program style, it requires a different framework: https://learn.microsoft.com/en-us/dotnet/core/tutorials/ ...
Read more >
You NEED to see this NEW C# Template in .NET 6.0 - YouTube
By the way, have you seen our new C# Tutorials? ... for manually adding using statements or main methods for simple console applications!...
Read more >
Creating a console app with Dependency Injection in .NET Core
The simple one: use the Console Application template and add dependency injection to it; The hybrid: use the Console Application template and ...
Read more >
Console templates
Console templates are the most powerful way to create templates that can be easily ... Prometheus comes with an example set of consoles...
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