dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.25k stars 5.89k forks source link

Please document how to change default console template. #26313

Closed alexanderpino closed 2 years ago

alexanderpino commented 3 years ago

Could you please document how we can change the console template back to the 'classic' Program + Main.

adegeo EDIT

We've opened up a new issue specifically for voting on how you feel about the templates. #27420


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

tdykstra commented 3 years ago

@adegeo @BillWagner

KathleenDollard commented 3 years ago

There is no direct way to do this in .NET 6. There are two approaches:

We want feedback. Voting on this issue is one of the ways folks can provide feedback.

@tdykstra @BillWagner would you update the docs to indicate this, and let me know if you need anything from me.

BillWagner commented 3 years ago

For now, you can do this:

dotnet new console --framework net5.0

Or, any other older framework.

Then, you can change the TFM to .NET 6:

<TargetFramework>net6.0</TargetFramework>
adegeo commented 3 years ago

Use

dotnet new console --framework net5.0 --target-framework-override net6.0

This will generate the old-style template but force the framework in the project to net6.0

Walluce commented 3 years ago

Can you please post a link to where I can vote against this new "feature"?

svick commented 3 years ago

@Walluce If you want to suggest that the dotnet new console template should be changed, then the right repo would be dotnet/templating. There is already a somewhat related issue at https://github.com/dotnet/templating/issues/3654.

If you think the whole feature of top-level programs should be removed, then in theory, the right repo would be dotnet/csharplang. But since that feature is not really new (it has been released in C# 9.0 almost a year ago), I don't think a vote against it would have any effect at this point.

tdykstra commented 3 years ago

@svick The article asks for feedback as up/down votes on this issue -- see the Template feedback section, The reference is to using top-level statements in the new-project template, not to the top-level statements feature itself.

Walluce commented 3 years ago

Use

dotnet new console --framework net5.0 --target-framework-override net6.0

This will generate the old-style template but force the framework in the project to net6.0

This doesn't work :(

Walluce commented 3 years ago

dotnet new web -n Demo -f net5.0 --target-framework-override net6.0 --no-https For more information, run: dotnet new web -h

bynarie commented 2 years ago

There is no direct way to do this in .NET 6. There are two approaches:

* Copy the code that appears in this docs article.

  * Either leave out the usings or remove remove implicit usings from your project file

* Target .NET 5 in your template, and then change the framework to .NET 6 in your project file after the project is created

We want feedback. Voting on this issue is one of the ways folks can provide feedback.

@tdykstra @BillWagner would you update the docs to indicate this, and let me know if you need anything from me.

In my opinion, this should be an optional global setting in visual studio. The new style template is ugly and I dont think anyone likes this. Thank you!

dpugh commented 2 years ago

Or provide a multiple .Net 6.0 frameworks (classic and simplified) that provide different initial layouts for the program.cs.

lkmn-l9y commented 2 years ago

That's too bad😅

rposener commented 2 years ago

Where are args in the new format? How do you use Command

Feels like this was not a well-informed decision to change the default template.

hbrumleve commented 2 years ago

It doesn't feel like the people who built this feature actually build a lot of software from scratch frequently. It feels like you're just showing off what you can do instead of building a tool for professionals to use. This adds several minutes to my startup time every time and takes me out of my flow.

bynarie commented 2 years ago

Yes, this really is complete shit. I just dont understand why this template was changed. Its not logical. I hope if we get enough people complaining it will change. And, per https://docs.microsoft.com/en-us/dotnet/core/tutorials/top-level-templates , this is the page it directs us to to voice our opinion about this template, so this is the correct spot.

bravecobra commented 2 years ago

Adding a boolean parameter to each of the templates that toggles between the toplevel statement syntax and the old syntax should be fairly easy. Just a matter of wrapping a few extra lines around the toplevel code. Leave it toplevel default checked if you want. I'll uncheck it myself. Making old syntax harder to get back is certainly not creating good sentiment with a lot of developers.

The other alternative is writing an analyzer to detect the syntax and having a codefix to wrap the global syntax again. We do want to avoid the compile error having multiple entrypoints though.

rfvan commented 2 years ago

I agree with the sentiments of most of the others responding here - this is an awful change. Please give us a way to make the old template the default, and provide a "create invisible, magic, impossible to understand code-behind" setting for those who like the new template. This has made the simple console template virtually unusable without a lot of extra pushups.

AlexeiScherbakov commented 2 years ago

This template speed up project creating process, but it is completely useless.

  1. Application creation tooks less then 1% of all programming time
  2. Template does not have access to command line parameters
  3. Template hides function definition and return value logic (void no return value,int - return value stored in $LastExitCode PowerShell env var)

For me it is better to allow usage of global functions (it is allowed for C++/CLI)

int Main(string[] args)
{
    Console.WriteLine("Hello world");
}
DiverBW commented 2 years ago

The current trend in technology seems to favaor PFM (pure freaking magic) and in my opinion makes it far harder for someone new to any given technology to understand what is really going on. This is a prime example.

As others have said, I would ask that you make this and option. I will certainly choose the option of the old style Program.cs file.

ahwm commented 2 years ago

Please provide an option to make the old style the default. I will go back to the old style every single time. The new style is not readable without experience.

bravecobra commented 2 years ago

This is a closed issue on the documentation section. I doubt very much we'll heard here, even with the numerous comments already voiced. There must be another channel to have our opinion heard.

died commented 2 years ago

New template is bad but MS don't wanna chnage back, even give an option zzzz

ahwm commented 2 years ago

This is a closed issue on the documentation section. I doubt very much we'll heard here, even with the numerous comments already voiced. There must be another channel to have our opinion heard.

Sure, but they link to this issue here: https://docs.microsoft.com/en-us/dotnet/core/tutorials/top-level-templates#template-feedback

BillWagner commented 2 years ago

We are watching this discussion. It's one of a few places where we're listening.

bravecobra commented 2 years ago

I see 2 solutions to this issue.

The end result would be the same.

The latter would avoid having to change the existing templates, but it provides at least an easy way to get old syntax back, which is what users seem to want: getting easy access to old syntax.

calloncampbell commented 2 years ago

Go back to the old style or at least provide an option (UI project wizard and CLI) to choose which one.

onebiozz commented 2 years ago

I'm not a fan of this much abstraction, C# dev for years and im struggling to get the basics working. I would suggest taking "console template" back and adding in "Console template abstracted" or "console template simplified" or something for this. I'm fine abstracting away namespaces or abstracting down main but making me have to jump through unclear hoops to just specify what i want to include and what i don't want to include and when i'm in and out of main. At the very least let me change this without opening the project file in a separate editor and mess around with the XML.

died commented 2 years ago

Ok, I create a classic console template and put on marketplace. https://marketplace.visualstudio.com/items?itemName=Doomdied.ClassicConsole1 It should be save some time if you want old style on .NET 6 img img

bar10dr commented 2 years ago

I have tried getting used to the new templates, we all resist change and its important to have an open mind regarding changes. That being said, after having tried it for a while, I really dislike the new templates and global using.

The simpler you want to make it, the harder it becomes to understand what is actually going on. One one side you need magic for those who are just starting out in order to expand the userbase, on the other side I think you also need to cater for those who are not just starting out?

In my opinion the global using mechanic is a detriment to what .net and C# originally set out to do.

As a simple example, add a Timer in the "hidden" main and now you got a hidden global reference to System.Threading.Timer, create a new file and reference "using System.Timers", now you have a ambiguous reference with no clear way on how to resolve it beyond statically referencing System.Timers on every object.

Remove the Timer object in the "hidden main" again, and the global reference is still there with no obvious way to remove it?

This is not about Timers, but how this new functionality is making the language harder to use. Its more obfuscated and it adds friction to something that used to be smooth as silk.

The more magic you add the harder it is to deal with if you want to do anything else than make a little example program?

I understand the need to make the adoption more approachable, but there needs to be options for those who are not starting out as well? For those who want to make applications and not small one file scripts?

I want to tailor my program to my exact specifications, the recent changes makes it harder and more time consuming to do so; which I believe is the opposite effect of what the changes assume to achieve.

DiverBW commented 2 years ago

Excellent comments, bar10dr.

It almost seems like Microsoft thinks that what most developers actually code is the one line “Hello World” program, and have optimized everything to that end!

Sent from my iPhone

On Nov 19, 2021, at 5:55 AM, bar10dr @.***> wrote:

 I have tried getting used to the new templates, we all resist change and its important to have an open mind regarding changes. That being said, after having tried it for a while, I really dislike the new templates and global using.

The simpler you want to make it, the harder it becomes to understand what is actually going on. One one side you need magic for those who are just starting out in order to expand the userbase, on the other side I think you also need to cater for those who are not just starting out?

In my opinion the global using mechanic is a detriment to what C# originally set out to do.

As a simple example, add a Timer in the "hidden" main and now you got a hidden global reference to System.Threading.Timer, create a new file and reference "using System.Timers", now you have a ambiguous reference with no clear way on how to resolve it beyond statically referencing System.Timers on every object.

Remove the Timer object in the "hidden main" again, and the global reference is still there with no obvious way to remove it?

This is not about Timers, but how this new functionality is making the language harder to use. Its more obfuscated and it adds friction to something that used to be smooth as silk.

The more magic you add the harder it is to deal with if you want to do anything else than make a little example program?

I understand the need to make C# more approachable, but there needs to be options for those who are not starting out as well? For those who want to make applications and not small one file scripts?

I want to tailor my program to my exact specifications, the recent changes makes it harder and more time consuming to do so; which I believe is the opposite effect of what the changes assume to achieve.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

olivier-spinelli commented 2 years ago

This is awful! Thanks to @died for providing us a decent template. (Up to me it should declare the support of "MacOS" and "Linux" too!)

bynarie commented 2 years ago

I think the concensus here is clear folks =]

died commented 2 years ago

This is awful! Thanks to @died for providing us a decent template. (Up to me it should declare the support of "MacOS" and "Linux" too!)

I only tested on Windows, so... It will be added on next version (if need update)

bynarie commented 2 years ago

I find it interesting that if you browse to https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio?pivots=dotnet-6-0 , which is an official microsoft tutorial, it tells you how to create a new C# console application. If you scroll down to number (5) and (6) on the page, it tells you to remove to the pre-existing code (the new, 1-line crap code) and to replace it with the old style (the correct code). How about we just switch back to the old template so we can cut out a wasted step? =] I just find it funny that even the microsoft tutorial is telling you to remove the template code and replace it with old style.

Kuinox commented 2 years ago

I find it interesting that if you browse to https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio?pivots=dotnet-6-0 , which is an official microsoft tutorial, it tells you how to create a new C# console application. If you scroll down to number (5) and (6) on the page, it tells you to remove to the pre-existing code (the new, 1-line crap code) and to replace it with the old style (the correct code). How about we just switch back to the old template so we can cut out a wasted step? =] I just find it funny that even the microsoft tutorial is telling you to remove the template code and replace it with old style.

In other docs, they tell you to use the .NET 5 template, then update it to .NET 6:
https://github.com/dotnet/docs/blob/main/docs/core/tutorials/top-level-templates.md#use-the-old-program-style

I don't like the new template, if I want programming with implicitness everywhere, i'd use javascript not C#.
Please stop trying to force us these new features, with what happened recently, and this, you make me more and more willing to invest time in other technologies.

SergeyDavidovich commented 2 years ago

This is terrible. have you thought about the fact that Asp Net core applications is also a console. Why are you making life difficult for us? I use Visual Studio from 2002 year. Whose idea was it?

q00Dree commented 2 years ago

It's annoying to create project (-console or -webapi) and make this stupid work (removing usings "feature", creating normal Program and Startup ) everytime. Pls give us old style back...

Smurgl commented 2 years ago

I'm not sure what advantages this is bringing. As others have mentioned, one of the most difficult parts of learning in programming is when "magic happens". It's wired up in the background and it just works. That can be nice, but it makes it tough to understand how everything fits together and gives no pointers as to how to investigate issues.

All this is doing is creating confusion, hiding what's going on and is it really making things easier or better? It's less lines of code and, when I watched the video on this it made sense... but in practice I think it hinders development more than it helps.

Namespaces, usings, classes & methods are all fundamentals to learning programming so even for new developers who may just want a quick approach to try something out are missing out on those fundamentals. I feel like tutorials other than "Hello world" would need to work around this.

kzeitz commented 2 years ago

This is merely obfuscation. As someone who's been using c# since it's beta, it's clearly not magic just pointless. For seasoned developers it's a joke. For beginners it masks errors and causes confusion as to why things don't compile. The closer the error is to the point at which it occurs the easier it is to remedy.

bynarie commented 2 years ago

I seriously apologize to everyone for my constant commenting and rants. Do we even have an explanation for why this template was changed? I'm legitimately not being sarcastic but actually asking. Thanks

bravecobra commented 2 years ago

I seriously apologize to everyone for my constant commenting and rants. Do we even have an explanation for why this template was changed? I'm legitimately not being sarcastic but actually asking. Thanks

Have a look at https://github.com/dotnet/csharplang/issues/3117 None of these 3 reasons are valuable, desired or highly requested as far as I can see.

bravecobra commented 2 years ago

Funny how that issue is locked for comments for being "too heated".

C1rdec commented 2 years ago

Any updates from Microsoft?

Juniorsnet commented 2 years ago

C# is becoming more close to python, whats next? run directly .cs files from command line?

Kuinox commented 2 years ago

C# is becoming more close to python, whats next? run directly .cs files from command line?

I would use it a lot. If I was given the choice with the old, and new template, I would use both. What I dislike, is not having the choice of using the old template, and having to manually migrate the code. The new template is nice to make littles C# script. I prefer using the old template for more serious apps.

ahwm commented 2 years ago

C# is becoming more close to python, whats next? run directly .cs files from command line?

https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-05-12.md#simple-c-programs

https://github.com/dotnet/designs/blob/a27fd42a68370f315bc2293dc748145f4075697f/proposed/simple-csharp-programs.md

dongolojeno85 commented 2 years ago

This is confusing. Almost hit the wrong vote because the whole description is misleading.

"Template feedback The top-level template is a new feature in .NET 6. Add an up or down vote GitHub issue #26313 to voice your support for this feature." From https://docs.microsoft.com/en-us/dotnet/core/tutorials/top-level-templates

Kuinox commented 2 years ago

Instead of "voting the new template", why can't we have both ?

symbiotic commented 2 years ago

This is confusing. Almost hit the wrong vote because the whole description is misleading.

"Template feedback The top-level template is a new feature in .NET 6. Add an up or down vote GitHub issue #26313 to voice your support for this feature." From https://docs.microsoft.com/en-us/dotnet/core/tutorials/top-level-templates

Agreed. I suggest we redo the voting, in a new GitHub issue that does not conflict with the page asking for feedback. The page currently says "to voice your support for this feature", but this issue says "Could you please document how we can change the console template back to the 'classic' Program + Main". These votes are ambiguous.

This template is less usable, mainly because the arguments and return value are hidden.

I'm also concerned about the decision process at Microsoft, behind such a change making it into Visual Studio / .NET.

tdykstra commented 2 years ago

The comment in the templates article has been changed from:

The top-level template is a new feature in .NET 6. Add an up or down vote GitHub issue #26313 to voice your support for this feature.

to:

Top-level statements is a new feature in .NET 6. Add an up or down vote in GitHub issue #26313 to let us know if you support the use of this feature in project templates.