首页 > 解决方案 > dotnet:适用于 Windows 10 命令提示符,但不适用于 VSCode

问题描述

我开始了学习 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,但它可以从命令行工作。

一些信息:

据我所知,一切都是正确的,这里的答案对我不起作用:dotnet is not known as the name of a cmdlet

当我dotnet --version从命令提示符或 PowerShell 执行时,我的输出是:

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

有任何想法吗?

标签: c#.netvisual-studio-code.net-core

解决方案


我有同样的问题。我不确定这是否理想,但我发现这似乎可行。在文件 -> 设置 -> 首选项 -> 功能 -> 终端中,我将终端从集成更改为外部终端,它解决了问题。不过,我也可能会切换到 Visual Studio Community。

将终端更改为外部


推荐阅读