如何从命令行创建新的 dotnetcore EMPTY Web 项目模板

Ste*_*t_R 7 c# command-line asp.net-core asp.net-core-cli

在命令行我可以输入

dotnet new -t web
Run Code Online (Sandbox Code Playgroud)

搭建一个新的 ASP.NET Core Web 项目,但它包含“完整模板”(相当于在 Visual Studio 中创建一个新的 MVC 项目)。

在 Visual Studio 中,我也可以创建一个新的空项目(它只返回“Hello World”字符串响应)。

是否有等效的命令行选项来构建空项目?

我在这里dotnet new找到了该命令的文档,但似乎没有这样的选项

Lee*_*uns 14

回答

dotnet new web
Run Code Online (Sandbox Code Playgroud)

我是怎么想出来的

(如果 cli 发生变化,将来也可以使用 2 验证)

.netcore cli/shell 有一个实用程序,可以列出可以使用“new”创建的所有新模板/项目。使用它你可以找到空的网络应用程序创建命令

dotnet new -l 
Run Code Online (Sandbox Code Playgroud)

然后返回这个

Templates                                     Short Name           Language    Tags                  
--------------------------------------------  -------------------  ----------  ----------------------
Console Application                           console              [C#],F#,VB  Common/Console        
Class library                                 classlib             [C#],F#,VB  Common/Library        
WPF Application                               wpf                  [C#],VB     Common/WPF            
WPF Class library                             wpflib               [C#],VB     Common/WPF            
WPF Custom Control Library                    wpfcustomcontrollib  [C#],VB     Common/WPF            
WPF User Control Library                      wpfusercontrollib    [C#],VB     Common/WPF            
Windows Forms App                             winforms             [C#],VB     Common/WinForms       
Windows Forms Control Library                 winformscontrollib   [C#],VB     Common/WinForms       
Windows Forms Class Library                   winformslib          [C#],VB     Common/WinForms       
Worker Service                                worker               [C#],F#     Common/Worker/Web     
Unit Test Project                             mstest               [C#],F#,VB  Test/MSTest           
NUnit 3 Test Project                          nunit                [C#],F#,VB  Test/NUnit            
NUnit 3 Test Item                             nunit-test           [C#],F#,VB  Test/NUnit            
xUnit Test Project                            xunit                [C#],F#,VB  Test/xUnit            
Razor Component                               razorcomponent       [C#]        Web/ASP.NET           
Razor Page                                    page                 [C#]        Web/ASP.NET           
MVC ViewImports                               viewimports          [C#]        Web/ASP.NET           
MVC ViewStart                                 viewstart            [C#]        Web/ASP.NET           
Blazor Server App                             blazorserver         [C#]        Web/Blazor            
Blazor WebAssembly App                        blazorwasm           [C#]        Web/Blazor/WebAssembly
ASP.NET Core Empty                            web                  [C#],F#     Web/Empty             
ASP.NET Core Web App (Model-View-Controller)  mvc                  [C#],F#     Web/MVC               
ASP.NET Core Web App                          webapp               [C#]        Web/MVC/Razor Pages   
ASP.NET Core with Angular                     angular              [C#]        Web/MVC/SPA           
ASP.NET Core with React.js                    react                [C#]        Web/MVC/SPA           
ASP.NET Core with React.js and Redux          reactredux           [C#]        Web/MVC/SPA           
Razor Class Library                           razorclasslib        [C#]        Web/Razor/Library     
ASP.NET Core Web API                          webapi               [C#],F#     Web/WebAPI            
ASP.NET Core gRPC Service                     grpc                 [C#]        Web/gRPC              
dotnet gitignore file                         gitignore                        Config                
global.json file                              globaljson                       Config                
NuGet Config                                  nugetconfig                      Config                
Dotnet local tool manifest file               tool-manifest                    Config                
Web Config                                    webconfig                        Config                
Solution File                                 sln                              Solution              
Protocol Buffer File                          proto                            Web/gRPC              
Run Code Online (Sandbox Code Playgroud)


Nko*_*osi 2

更新

Microsoft 不再支持 yeoman,下面提供的链接将永久重定向到:

dotnet new


过时的答案

根据微软文档

与 Yeoman 一起构建项目

您还可以将Yeoman命令行工具yo与 Yeoman 生成器一起使用。

您将需要安装 Node.js 和 npm。

从那里运行 ASP.NET 生成器

yo aspnet
Run Code Online (Sandbox Code Playgroud)

生成器显示一个菜单。向下箭头指向空 Web 应用程序项目,点击Enter,然后为您的项目命名。Yeoman 将搭建该项目及其支持文件。