net core 安装web模板

时间:2023-01-26 11:54:13

---恢复内容开始---

今天想试试在Linux用C#开发WebAPI,查了下,要用:

dotnet new -t Web

来建立工程,结果我试了下,出来这段:

Invalid input switch:
-t
Web
Run dotnet new --help for usage information.
See https://aka.ms/dotnet-install-templates to learn how to install additional template packs.

后面给了个提示:请到https://github.com/aspnet/Tooling/blob/master/missing-template.md学习怎么安装模板,进入一看就一句:

dotnet new -i Microsoft.DotNet.Web.ProjectTemplates..x::1.0.-*
net core 安装web模板

就这还专门让我进网站来"学"...

输入指令,得到下面结果:

  Restoring packages for /root/.templateengine/dotnetcli/v2.0.0/scratch/restore.csproj...
Installing Microsoft.DotNet.Web.ProjectTemplates.1.x 1.0.0-beta2-20170629-269.
Generating MSBuild file /root/.templateengine/dotnetcli/v2.0.0/scratch/obj/restore.csproj.nuget.g.props.
Generating MSBuild file /root/.templateengine/dotnetcli/v2.0.0/scratch/obj/restore.csproj.nuget.g.targets.
Restore completed in 1.82 sec for /root/.templateengine/dotnetcli/v2.0.0/scratch/restore.csproj. Templates Short Name Language Tags
------------------------------------------------------------------------------------------------
Console Application console [C#], F#, VB Common/Console
Class library classlib [C#], F#, VB Common/Library
Unit Test Project mstest [C#], F#, VB Test/MSTest
xUnit Test Project xunit [C#], F#, VB Test/xUnit
ASP.NET Core Empty web [C#], F# Web/Empty
ASP.NET Core Web App mvc [C#], F# Web/MVC
ASP.NET Core Web App razor [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
ASP.NET Core Web API webapi [C#], F# Web/WebAPI
global.json file globaljson Config
Nuget Config nugetconfig Config
Web Config webconfig Config
Solution File sln Solution
Razor Page page Web/ASP.NET
MVC ViewImports viewimports Web/ASP.NET
MVC ViewStart viewstart Web/ASP.NET Examples:
dotnet new mvc --framework netcoreapp1.1 --auth Individual
dotnet new web
dotnet new --help

  看来是安装成功了.

建立工程运行试试:

dotnet new web
dotnet restore
dotnet run

运行成功.显示监听了本机5000端口

打开试试: http://localhost:5000

可以看到页面,至此安装模板算是成功了