How to create a .NET 5.0 Console application in Visual Studio 2019

Nicholas Piazza 541 Reputation points
2021-01-01T20:27:19.26+00:00

I have Visual Studio 2019 Community, version 16.8.3. How do I use it to create a .NET 5.0 Console application without editing the project file? If I choose the Console .NET Core template, it creates a project file targeted for .NET Core 3.1 (netcoreapp3.1). To use .NET 5.0 and C# 9 features, I have to edit that project file to read "net5.0" (and LanguageVersion 9.0). I was hoping with the release of .NET 5.0 that there would be new templates in Visual Studio to directly create .NET 5.0 projects (and not just Console, but also Windows, UWP, WPF, etc.)

Developer technologies | Visual Studio | Other
Developer technologies | C#
{count} votes

Accepted answer
  1. Jaliya Udagedara 2,836 Reputation points MVP Volunteer Moderator
    2021-01-01T20:56:27.15+00:00

    Unfortunately, Visual Studio 2019 (even the latest preview) doesn't default to .NET 5.

    But you can create your own Project template that targets .NET 5. Please follow this documentation to achieve that: Tutorial: Create a project template

    1 person found this answer helpful.
    0 comments No comments

7 additional answers

Sort by: Most helpful
  1. kirilllivanov 6 Reputation points
    2021-02-23T22:34:45.963+00:00

    You can enable all .NET Core and .NET 5.0 templates:

    Tools > Options > Preview Features > “Show all .NET Core templates in the New project dialog (requires restart)”

    1 person found this answer helpful.
    0 comments No comments

  2. Viorel 122.6K Reputation points
    2021-01-01T20:32:12.017+00:00

    Instead of editing the project file manually, try creating a new .NET Core project, go to Project Properties and change the Target framework to “.NET 5.0”.

    0 comments No comments

  3. Nicholas Piazza 541 Reputation points
    2021-01-01T20:37:21.97+00:00

    Either way, it's a change to the project file after creating one from the template. Is there a way to create a new template file that shows up in the list of templates when you start Visual Studio that automatically sets up the project file for .NET 5.0 when a new project is created?

    0 comments No comments

  4. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2021-01-01T22:09:40.853+00:00

    Hello @Nicholas Piazza

    See the following project for a sample console app using .NET 5, C# 9.

    For you project, double click on the project to open it up and replace the contents with the following. Now to make it easy for other project, select all text in the .csproj file, drag it to the toolbox. Now when needed in another project delete that project's .csproj file contents and drag in the code from the toolbox. If you right click on that item you can rename it e.g.

    52765-proj.png

    This is the project file contents

    <Project Sdk="Microsoft.NET.Sdk">  
      
      <PropertyGroup>  
        <OutputType>Exe</OutputType>  
    	  <LangVersion>9.0</LangVersion>  
    	  <TargetFramework>net5.0</TargetFramework>  
      </PropertyGroup>  
      
    </Project>  
    

    For Windows Forms

    <PropertyGroup>  
    <OutputType>WinExe</OutputType>  
      <LangVersion>9.0</LangVersion>  
      <TargetFramework>net5.0-windows</TargetFramework>  
    <UseWindowsForms>true</UseWindowsForms>  
    </PropertyGroup>  
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.