简体   繁体   English

如何从 powershell 运行 do.net new?

[英]How to run dotnet new from powershell?

I have installed do.net-sdk-7.0.101-win-x86.exe by downloading it and running it.我已经通过下载并运行它安装了do.net-sdk-7.0.101-win-x86.exe。 This is verified by the fact that if I try to run it again it goes to a different screen where I can modify it.事实证明,如果我再次尝试运行它,它会转到另一个我可以修改它的屏幕。

I am attempting to follow the instructions for a course on Udemy on creating a console app, however I am purposely doing something different.我正在尝试按照 Udemy 上有关创建控制台应用程序的课程的说明进行操作,但是我故意做一些不同的事情。 In the course the instructor is explaining to set everything up under his user directory (in windows).在课程中,讲师正在解释如何在他的用户目录(Windows 中)下设置所有内容。 I would like not to do that.我不想那样做。

The reason I don't want to do that Is I have a folder already that has my work stuff in it and I want this to work for my work stuff also.我不想这样做的原因是我已经有一个文件夹,里面有我的工作资料,我希望它也适用于我的工作资料。 For me, this folder is C:\SourceCode\ (something).对我来说,这个文件夹是 C:\SourceCode\(某物)。 I have a folder called GitHub that has all the repositories I've downloaded for work and I have another folder called 'Local' which I am using for learning.我有一个名为 GitHub 的文件夹,其中包含我为工作下载的所有存储库,还有另一个名为“本地”的文件夹,我正在使用它进行学习。 So, this is the output I try to create a new HelloWorld console app:所以,这是 output 我尝试创建一个新的 HelloWorld 控制台应用程序:

PS C:\SourceCode\Local\dotnet-course-code> dotnet new -n HelloWorld
The command could not be loaded, possibly because:
  * You intended to execute a .NET application:
      The application 'new' does not exist.
  * You intended to execute a .NET SDK command:
      No .NET SDKs were found.

Download a .NET SDK:
https://aka.ms/dotnet-download

Learn about SDK resolution:
https://aka.ms/dotnet/sdk-not-found
PS C:\SourceCode\Local\dotnet-course-code>

I did some googling already to try to solve the problem, One insightful post had me run the following command which I believe proves that the do.net thing was installed (but I could be wrong)我已经做了一些谷歌搜索来尝试解决这个问题,一篇有见地的帖子让我运行了以下命令,我相信它证明了 do.net 东西已经安装了(但我可能是错的)

PS C:\SourceCode\Local\dotnet-course-code> Get-Command dotnet |Format-List


Name            : dotnet.exe
CommandType     : Application
Definition      : C:\Program Files\dotnet\dotnet.exe
Extension       : .exe
Path            : C:\Program Files\dotnet\dotnet.exe
FileVersionInfo : File:             C:\Program Files\dotnet\dotnet.exe
                  InternalName:     .NET Host
                  OriginalFilename: .NET Host
                  FileVersion:      6,0,922,41905 @Commit: 163a63591cf9e9b682063cf3995948c2b885a042
                  FileDescription:  .NET Host
                  Product:          Microsoft® .NET Framework
                  ProductVersion:   6.0.9 @Commit: 163a63591cf9e9b682063cf3995948c2b885a042
                  Debug:            False
                  Patched:          False
                  PreRelease:       False
                  PrivateBuild:     False
                  SpecialBuild:     False
                  Language:         English (United States)

I would like to know why this doesn't work as expected.我想知道为什么这不能按预期工作。 Note this is on a brand new machine running windows 11 and these commands are being run in powershell.请注意,这是在运行 windows 11 的全新机器上,这些命令正在 powershell 中运行。

This is the crucial part of the error message:这是错误消息的关键部分:

  * You intended to execute a .NET SDK command:
      No .NET SDKs were found.

In order to create source-code projects , you need to download the .NET SDK , specifically.为了创建源代码项目,您需要下载.NET SDK

The presence of do.net.exe alone does not imply that an SDK installed, given that it is possible to install a runtime only.仅存在do.net.exe并不意味着安装了SDK ,因为可以仅安装运行时

If you run do.net --info , you'll see what SDKs and runtimes are installed.如果您运行do.net --info ,您将看到安装了哪些 SDK 和运行时。

If no SDK is listed, you'll have to install one.如果没有列出 SDK,则必须安装一个。

Update : As you note, the problem was that you had accidentally created parallel installations (a x86 version alongside an x64 one), and the one you tried to use lacked an SDK.更新:正如您所注意到的,问题是您不小心创建了并行安装(x86 版本和 x64 版本),而您尝试使用的版本缺少 SDK。


Once one is installed, your command should work if you also specify a project type , which is required , as topsail points out;一旦安装了一个,如果您还指定了一个项目类型,您的命令应该可以工作,正如topsail指出的那样, 这是必需的; eg, to create a console application in subfolder HelloWorld :例如,在子文件夹HelloWorld中创建一个控制台应用程序:

# OK, once an SDK is installed.
dotnet new console -n HelloWorld

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM