Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer to use project templates created in previous .NET versions #27065

Closed
EvaldasPovilaitis opened this issue Aug 9, 2022 · 6 comments
Closed
Assignees
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@EvaldasPovilaitis
Copy link

Is your feature request related to a problem? Please describe.

A lot of people dislike .NET 6 templates (dotnet/docs#27420). Some minimum progress was made to bring portions of the old templates back with the following option

image

Unfortunately the end product is far from what is expected by the community and what was voted for already by more than 1K people.

Describe the solution you'd like

An option to use templates as with .NET 5 without top-level statements and implicit usings. Exactly for what voted more than 1K people.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Aug 9, 2022
@MojoMoe
Copy link

MojoMoe commented Aug 21, 2022

My PC Setup:
Windows 11 (all current/latest updates installed)
.NET SDK 6.04
PowerShell v7.2.6
Visual Studio Code 2022 v1.70.2

I am just starting out my dotnet journey and started a course on LinkedIn Learning today. When the instructor uses this command in Windows CMD with dotnet version 5.0:
dotnet new console

For the instructor the generated program.cs file contains the following code:


using System;

namespace HelloWorld
{

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
    }
}

}


When I run the same code in VS Code Terminal:
dotnet new console

The generated program.cs file contains this code:


// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");


I was expecting to see the same code generated for me as it was for the instructor (see above code). Am I doing anything wrong? I am not sure if it's a template issue (I currently don't know anything about dotnet templates as I've only just started out learning dotnet/C# today!) or if this is the normal expected behaviour of dotnet 6.0.4. Not sure if this is a dotnet issue or something not right on my Windows 11 build.

PS. I have added lines to make the code clearer because GitHub is messing up the code.

@AptiviCEO
Copy link

AptiviCEO commented Aug 21, 2022

@MojoMoe You're running to this: dotnet/docs#27420

.NET SDK 6.0.xxx uses a new Console template using the top-level statements. It's neither Windows 11 nor Visual Studio to blame; it's just the console template.

If you have .NET SDK 6.0.300 or higher, would dotnet new console --use-program-main give you the old-style Program.cs instead of the top-level statements version?

This is explained here: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-new-sdk-templates#console

@MojoMoe
Copy link

MojoMoe commented Aug 22, 2022

@MojoMoe You're running to this: dotnet/docs#27420

.NET SDK 6.0.xxx uses a new Console template using the top-level statements. It's neither Windows 11 nor Visual Studio to blame; it's just the console template.

If you have .NET SDK 6.0.300 or higher, would dotnet new console --use-program-main give you the old-style Program.cs instead of the top-level statements version?

This is explained here: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-new-sdk-templates#console

Hi @EoflaOE Thanks very much for your response, it's very helpful. I will try that. Much appreciated :)

@baronfel
Copy link
Member

Closing as there is a documented way to get the old template style.

@baronfel baronfel closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2024
@joscha999
Copy link

Closing as there is a documented way to get the old template style.

I checked the documentations listed in this thread, linked sub-pages in regards to implicit usings and did a quick search but was unable to find documentation about it.

Mind posting the documentation on how to use the old template style in regards to implicit usings? I can see options to use the old Program with main instead of top level statements but no option to disable implicit usings either via a different template or a template setting.

@KalleOlaviNiemitalo
Copy link

global using is a C# 10 feature, so dotnet new console --langVersion=9 emits C# code that does not use it. Afterwards, you can delete the LangVersion property from the project file if you want to use a higher version.

However, dotnet new web doesn't seem to offer a similar option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

6 participants