gpt4 book ai didi

c# - 在 Visual Studio 2019 中找不到 .NET 5.0 控制台应用程序项目模板

转载 作者:行者123 更新时间:2023-12-04 04:24:58 29 4
gpt4 key购买 nike

我目前正在尝试在 Visual Studio 2019 中创建 C# .NET 5.0 控制台应用程序,并且该选项没有像我预期的那样出现在项目模板下。
我下载了 Visual Studio Professional 2019 版本 16.9.4(来自 https://visualstudio.microsoft.com/downloads/)并选择了所有要安装的工作负载,然后我安装了 SDK 5.0.202、ASP.NET Core Runtime 5.0.5、.NET Desktop Runtime 5.0.5 和.NET 运行时 5.0.5(来自 https://dotnet.microsoft.com/download/dotnet/5.0)。
当我转到文件 -> 新建 -> 项目并搜索“控制台应用程序”时,C# 没有默认的“控制台应用程序”项目模板。我能找到的最接近的是 C#、VB 和 F# 的“控制台应用程序 (.NET Framework)”和 C++ 的“控制台应用程序”。如果我为 C# 选择“控制台应用程序(.NET Framework)”,我可以选择的最新框架是“.NET Framework 4.8”。
实际结果:项目模板
Actual Outcome: Project Templates
实际结果:框架
Actual Outcome: Frameworks
我与没有遇到此问题的开发人员进行了比较,当他们为 C# 选择“控制台应用程序(.NET Framework)”时,他们看到了相同的框架限制,但也能够看到项目模板“控制台应用程序” C#(没有“.NET Framework”)并按预期选择“.NET 5.0(当前)”作为目标框架。他们安装和更新的内容似乎没有明显不同,我们对命令提示符命令“dotnet --info”的结果匹配,并且他们没有在“关于”下列出任何“已安装产品”或在“个人组件”下列出我失踪的安装程序。
预期结果:项目模板
Expected Outcome: Project Templates
预期结果:框架
Expected Outcome: Frameworks
我尝试卸载并重新安装所有内容,彻底安装每个工作负载以及看起来可能相关的其他单个组件,并确保“工具 -> 选项 -> 环境 -> 预览功能 -> 显示所有 .NET Core 模板”新项目对话框(需要重新启动)”复选框被选中。
有谁知道我缺少哪个步骤阻止我使用 .NET 5.0 在 C# 中创建控制台应用程序项目模板?

最佳答案

背景——这个改变/破坏,微软故意选择的问题你可以阅读更多hereissue reported here但是您可以使用下面列出的 2 个选项来解决此问题,即 A) 启用它或 B) 通过修复工具将其添加到 VS
建议清除 VStudio Cache 的 -- kill dev process & clear cache在重新/启动 VS 之前
在 powershell 中以管理员身份运行此 cmd

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.



现在请继续这些步骤/选项
  • 选项 1:您可能需要 enable这个选项...

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


    Enable the option
  • 选项 2: Install通过 Visual Studio Installer像这样..

  • 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

    安装程序启动后,检查是否为桌面和控制台选择了 .NET Core 工作负载。如下所示。在右侧 Pane 中,您需要选中正确的框
    Select the core tools
    清除 Visual Studio 组件缓存(以及可选的所有模板)
    现在,如果您已经按照上述步骤操作,那么验证您在 Visual Studio 安装程序上是否选中了右上角的“.net-Desktop development”复选框: 删除缓存并恢复
    即你可以 restore the template在 VS2017/2019 中然后再试一次。

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


    请引用以下步骤:
  • DELETE ItemTemplatesCache , ProjectTemplatesCache文件夹 Ent.Prof .版本等。C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE. & C:\Users\<USERNAME>\AppData\Local\Microsoft\VisualStudio\16.0_93de0ddd
  • 在命令提示符下,导航到 devenv.exe 的位置。该文件位于\Common7\IDE 中。
  • 键入/运行此命令 devenv /installvstemplates并按 Enter。

  • .Net Desktop Dev Workload
    仅供引用 - 您的 templates cache在这里,包含以模板文件夹中存档的 zip 文件命名的文件夹。
    您将需要管理员权限才能进行编辑/ delete .
    // templates cache Microsoft
     %AppData%\Microsoft\VisualStudio\{some_version}\ItemTemplatesCache\

    //用于验证、修复/重新安装或删除的模板路径
     %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\


    选项 3:调试你的环境。 Template Config folder检查/诊断版本:

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


    下载并运行 collect.exe - https://aka.ms/vscollect - 并在 github 上与 MS 共享在 %TEMP%\vslogs.zip 中创建的日志文件
    仅供引用 - 这就是您在 Visual Studio 中的模板文件夹结构应该是什么样子。
    └───mytemplate
    │ console.cs
    │ readme.txt

    └───.template.config
    template.json

    关于c# - 在 Visual Studio 2019 中找不到 .NET 5.0 控制台应用程序项目模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67408301/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com