15

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?

Michael Rovinsky
  • 6,807
  • 7
  • 15
  • 30
Richard Chang
  • 151
  • 1
  • 4
  • You could try this suggestion: https://stackoverflow.com/questions/67367636/visual-studio-2019-installer-setup-templates-missing – Albert D. Kallal May 06 '21 at 00:27
  • @Richard Chang, based on my test, I can create .net 5 console project if I install the workloads **.NET desktop development** and the Individual components **.NET 5.0 Runtime**. Also, please choose All languages to c#, All Projects to console to check it again if you have the temple. – Jack J Jun May 06 '21 at 05:53
  • @AlbertD.Kallal I tried this and it did not fix the issue. – Richard Chang May 06 '21 at 16:18
  • @JackJJun-MSFT .NET 5.0 Runtime is checked in Individual components, and just to be exhaustive, I checked all workloads, including .NET desktop development. When I set the filters to C# and Console, the only project templates that appear are "Console App (.NET Framework)" and "Workflow Console Application". – Richard Chang May 06 '21 at 16:25
  • Have you checked this question https://developercommunity.visualstudio.com/t/visual-c-net-core-templates-missing-1/778309? Do you maybe have some group policy that restricts access of VS to .NET Core? – Andrii Litvinov May 12 '21 at 19:55
  • @RichardChang can you please check the frameworks/libraries picked in your Visual Studio Installer > "Individual components" tab and share with us? – nunohpinheiro May 12 '21 at 20:05
  • @AndriiLitvinov Yes, I have looked at this. I have tried all these suggestions and they do not fix the issue. – Richard Chang May 14 '21 at 15:52
  • 2
    @NPinheiro I have actually tried selecting all of them (choosing the latest ones for the duplicates) and even that does not fix the issue. In addition to this, I have tried doing a regular install on a new virtual machine, and the issue does not occur ("console app" does appear), so this is not an issue with what I'm selecting for installation, it's an issue with some configuration in my machine specifically. – Richard Chang May 14 '21 at 15:56

7 Answers7

14

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

Transformer
  • 6,963
  • 2
  • 26
  • 52
  • Thanks for the response. Everything suggested has been checked and do not fix the issue (some outlined in the OP). I've tried every combination of remove/install/modify/repair, including checking all the workloads and components possible. We can rule out missing a step in the setup, because I was able to get Console App appearing on a different machine, so it's specific to my machine's existing settings. I've compared version details with a machine w/o this issue and they match. I can also technically create a .NET 5 console app with workarounds, so it's just a project template display issue. – Richard Chang May 14 '21 at 16:15
  • @RichardChang thats odd.. but I would suggest you mention it the MS team directly https://github.com/dotnet/sdk/issues/17097 .. it maybe a registry thing. I will add some more detail - deep trouble shooting for you shortly, but it involves the templates JSON file and config files. – Transformer May 14 '21 at 18:03
2

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.

Soleil
  • 6,404
  • 5
  • 41
  • 61
  • Thanks for the response. All variations of installing, uninstalling, repairing, and modifying with different/all workloads has been attempted already. I'm able to do the same thing on other machines and virtual machines without the issue, so it's not caused by an oversight with the installation process. – Richard Chang May 18 '21 at 16:07
  • @RichardChang Did you try to delete the user cache as specified in my answer ? – Soleil May 19 '21 at 23:21
1

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.

Andrii Litvinov
  • 12,402
  • 3
  • 52
  • 59
  • 1
    Thanks for the reply. Yes, I have been using this workaround, so the issue is just figuring out why the option doesn't appear in the Visual Studios UI. I've tried running the installer as admin and the same issue happens. – Richard Chang May 14 '21 at 15:58
  • @RichardChang have you tried removing all the .net core sdks and all their traces from the system, uninstalling VS with all traces and then reinstalling it again? – Andrii Litvinov May 14 '21 at 18:33
0

I checked and I am able to create dotnet5.0 console application with visual studio version 16.9.2 and SDK version 5.0.201. I think there is some installation conflict on your end. You can try uninstalling the SDK and reinstalling visual studio or updating it to latest version and downloading latest SDK. Also check if SDK is getting installed on your system under

C:\Program Files\dotnet\sdk[your SDK version]\

Harkirat singh
  • 599
  • 6
  • 19
0

After a year of just dealing with it, I FINALLY FIGURED IT OUT.

Go to C:\Program Files\dotnet\templates then open every folder there. Apparently it was a permission issue because I was getting:

[Window Title]
6.0.6
[Main Instruction]
You don't currently have permission to access this folder.
[Content]
Click Continue to permanently get access to this folder.
[Continue] [Cancel]

You don't currently have permission to access this folder.

After selecting Continue for each folder, everything started working.

The error that resulted from running dotnet new --list is what gave me the heads up. dotnet new --list

Derek Ziemba
  • 2,467
  • 22
  • 22
0

My solution was deleting C:\Users\USERNAME.templateengine\

Marco
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 11 '22 at 00:01
-1

I have VS 2019 version 16.9.5 when I seen your post. I am using console app for my sample projects. I have tried it and able to achieve what you are looking for. I would recommend to update your VS to 16.9.5 and give it a try.


My VS 2019 version:

enter image description here


Creating Console app in VS 2019 16.9.5:

enter image description here


Finally it has created a console app project with target framework as .net 5.0

enter image description here

Chinmay T
  • 745
  • 1
  • 9
  • 17
  • We know it's not related to VS 16.9.4 because when Richard installed 16.9.4 in a fresh VM, the issue went away. So it's something specific to his current OS, registry, or configuration. – Jordan Rieger May 14 '21 at 18:14