【发布时间】:2021-11-11 00:38:02
【问题描述】:
我开始了学习 DotNet 的旅程,并在 MS 网站上做一个演示应用程序,这里是:https://docs.microsoft.com/en-us/learn/modules/create-razor-pages-aspnet-core/3-exercise-create-new-aspnetcore-app。
尝试在 VSCode 中运行 dotnet 时出现以下错误:
The term 'dotnet' is not recognized as the name of a cmdlet,但它可以从命令行运行。
一些信息:
- 在 Windows 10(管理员或非管理员)或 Windows PowerShell 中打开命令提示符时,会找到
dotnet --help并做出响应。 - 为我自己的用户和系统帐户正确设置了 dotnet 的路径(只是为了确定)。
- 工具在我的用户路径中设置如下:
%USERPROFILE%\.dotnet\tools。 - 我以管理员和普通用户的身份尝试了 PowerShell 和命令提示符,以检查是否可能是用户权限提升问题导致它在 VSCode 中失败,但事实并非如此。这两种用户类型都在 VSCode 之外工作。
据我所知,一切都是正确的,这里的答案对我不起作用:dotnet is not recognized as the name of a cmdlet
当我从命令提示符或 PowerShell 执行 dotnet --version 时,我的输出是:
C:\Users\bobandalice>dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.100
Commit: 9e8b04bbff
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19042
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.100\
Host (useful for support):
Version: 6.0.0
Commit: 4822e3c3aa
.NET SDKs installed:
6.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
在 VSCode 中执行相同操作时,输出是这样的:
PS C:\Users\bobandalice\OneDrive\dotnetapps\RazorPagesPizza> dotnet --info
dotnet : The term 'dotnet' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ dotnet --info
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (dotnet:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
有什么想法吗?
【问题讨论】:
-
问:您是否尝试过在您的工作站上卸载/重新安装 .Net Core/.Net 5.x - 包括 Microsoft Visual C++ Redistributable (x86)? stackoverflow.com/a/42800519/421195
-
感谢您的评论。我也刚刚再次尝试过 - 仍然是同样的问题。不过,我使用的是 DotNet 6,而不是 5。另外 - 正如我所说,我可以从命令行完成我需要做的所有事情,但不能从 VSCode 完成。这似乎是 VSCode 的 C# 扩展可能有一些配置问题?
-
我喜欢 VSCode,我每天都在使用它。但对于 C# 开发,我通常更喜欢使用 MSVS(MSVS Pro 或 MSVS Express)。问:这对你来说是一个选择吗?
-
如果我不需要昂贵的许可证,我可以。正如您从问题中看到的那样,我不是 DotNet 开发人员。我现在只是在学习。我最大的客户将在 3 年内将他们的企业系统重写为 DotNet,到那时我需要相关。他们将从 CodeIgniter 和 PHP 迁移。我现在才开始准备。
-
我现在正在安装 MSVS Community 2022。不会解决我的问题,但愿意测试新事物。
标签: c# .net visual-studio-code .net-core