Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find .NET 5.0 Console App project template in Visual Studio 2019

I'm currently trying to create a C# .NET 5.0 Console Application in Visual Studio 2019, and the option does not appear under project templates as I expect it to.

I downloaded Visual Studio Professional 2019 Version 16.9.4 (from https://visualstudio.microsoft.com/downloads/) and selected all workloads to be installed, then I installed SDK 5.0.202, ASP.NET Core Runtime 5.0.5, .NET Desktop Runtime 5.0.5, and .NET Runtime 5.0.5 (from https://dotnet.microsoft.com/download/dotnet/5.0).

When I go to File -> New -> Project and search for "Console Application", there is no default "Console Application" project template for C#. The closest I can find is "Console Application (.NET Framework)" for C#, VB, and F# and "Console Application" for C++. If I select "Console Application (.NET Framework)" for C#, the latest Framework that I can choose is ".NET Framework 4.8".

Actual Outcome: Project Templates

Actual Outcome: Project Templates

Actual Outcome: Frameworks Actual Outcome: Frameworks

I compared notes with a developer who did not run into this problem, and they see the same framework restriction when they select "Console Application (.NET Framework)" for C#, but is also able to see the project template "Console Application" for C# (without ".NET Framework") and select ".NET 5.0 (Current)" as the target framework as expected. Nothing about what they installed and updated appeared to be noticeably different, our results for the command prompt command "dotnet --info" matched, and they did not have any "Installed products" listed under "About" or "Individual Components" listed under the installer that I was missing.

Expected Outcome: Project Templates

Expected Outcome: Project Templates

Expected Outcome: Frameworks

Expected Outcome: Frameworks

I have tried uninstalling and reinstalling everything, exhaustively installing every workload as well as additional individual components that looked potentially relevant, and making sure that the "Tools -> Options -> Environment -> Preview Features -> Show All .NET Core templates in the New project dialog (requires restart)" checkbox is checked.

Does anyone know what step I'm missing that is preventing me from creating a Console Application project template in C# using .NET 5.0?

like image 315
Richard Chang Avatar asked May 05 '21 20:05

Richard Chang


People also ask

How do I know my project template in Visual Studio 2019?

For example, you can right-click the project > click properties > select Application and see(refer to) the related information, for example, Output type -- Windows Application, Console Application, Class Library… Or you can find some related information about the project type from items, files etc.


Video Answer


3 Answers

Background -- This change/broke, issue that Microsoft opted deliberately you can read more here and the issue reported here but you can fix this with the 2 options listed below, i.e. A) enable it OR B) add it to VS via the repair tool

suggest clear VStudio Cache's -- kill dev process & clear cache before re/starting VS

run this cmd as admin in powershell

Get-Process devenv | Foreach-Object { $_.CloseMainWindow() | Out-Null }

Then DELETE ItemTemplatesCache, ProjectTemplatesCache folder ent. prof. etc.. C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE.


Now please Proceed with these Steps/Options


  • Option 1: you may have to enable this option...

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

Enable the option


  • Option 2: Install via Visual Studio Installer like so..

You can install missing workloads using the repair VS (this will also update the installer) and make sure you check the optional packages you want from the VS Installer tool please see this

repair the VS install


after the installer starts check if the .NET Core workload is selected for desktop and console.. like below.. on the right pane you will need to check the correct boxes Select the core tools

Clear Visual Studio Component Cache (& optionally all Your templates)

Now, if you have already followed the above steps, then verifying you selected the checkbox of ".net-Desktop development" on top right is selected or not on Visual Studio installer: delete the cache and restore

i.e. you could restore the template in VS2017/2019 then try it again.

Kill dev process first run this Get-Process devenv | Foreach-Object { $_.CloseMainWindow() | Out-Null }

Please refer to the following steps:

  1. DELETE the ItemTemplatesCache, ProjectTemplatesCache folder Ent. or Prof. version etc.. C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE. & C:\Users\<USERNAME>\AppData\Local\Microsoft\VisualStudio\16.0_93de0ddd
  2. In the command prompt, navigate to the location of devenv.exe. This file is located in \Common7\IDE.
  3. Type/Run this command devenv /installvstemplates and press Enter.

.Net Desktop Dev Workload

FYI - your templates cache is here, containing folders named after the zip files from your archives in the template folder. you will need admin privilege's for edits/delete.

//templates cache Microsoft

 %AppData%\Microsoft\VisualStudio\{some_version}\ItemTemplatesCache\

//templates path for verification, repair/reinstall or delete

 %USERPROFILE%\Documents\Visual Studio 2019\Templates\ProjectTemplates
 %USERPROFILE%\Documents\Visual Studio 2019\Templates\ItemTemplates
 %ProgramFiles(x86)%\Microsoft Visual Studio\2019\<edition>\Common7\IDE\ItemTemplates\
 %ProgramFiles(x86)%\Microsoft Visual Studio\2019\<edition>\Common7\IDE\ProjectTemplates\

Option 3: debugging your env. Template Config folder

Checking/Diagnosing the version:

run this dotnet --version install the correct core version https://dotnet.microsoft.com/download/dotnet/5.0 more here this dotnet new -u will tell you which templates are installed, you can uninstall, clear the packages cache, restart and reinstall with the repair tool.

Download and run collect.exe - https://aka.ms/vscollect - and share the log file created in %TEMP%\vslogs.zip with MS on github

FYI - This is what your template folder structure in visual studio should look like.

└───mytemplate
    │   console.cs
    │   readme.txt
    │
    └───.template.config
            template.json

like image 99
Transformer Avatar answered Oct 10 '22 08:10

Transformer


Eventually clear the MEF component cache, manually or with this extension.

But most likely something is wrong in the user cache at C:\Users\USERNAME\AppData\Local\Microsoft\VisualStudio\16.0_93de0ddd, which includes in particular InstalledTemplates.json and privateregistry.bin.

Try and rename (or delete) the folder, (or one the the two mentionned files to narrow the problem down), while VS is off, and restart VS. Only make sure that you have the proper workloads installed and the .net 5 from VS.

like image 23
Soleil Avatar answered Oct 10 '22 07:10

Soleil


While it can be hard to tell what's exactly the issue with VS or local environment you have, it should be possible to temporary create projects with dotnet cli:

dotnet new console --output <project-dir>

If you would want to add it to an existing solution run

dotnet sln <solution-name>.sln add <project-dir>

The console app project file is very simple, so you can even create it manually, or create a project from any existing template and replace the contents with following asa workaround:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

</Project>

And maybe one more thing you could try is to run the VS installer as admin or ensure that it can install and access all the required components.

like image 1
Andrii Litvinov Avatar answered Oct 10 '22 09:10

Andrii Litvinov