.Net5透過dotnet cli指令產生專案

 

首先確認目前已經安裝好.net 5的sdk或是runtime
支援的OS





在指定目錄下用cmd開啟
並下以下指令

1
2
3
4
dotnet new sln
dotnet new webapi --name Web
dotnet sln add [csproj-file-location]
dotnet run Web.csproj

Step1.
產生空專案預設就會以目前所在folder 的名稱來命名
dotnet new sln


Step2.
創建「ASP.NET Core Web API」專案範本
dotnet new webapi --name Web




Step3.
將我們創建好的web api專案加進我們第一步創建的.net5方案
dotnet sln add [csproj-file-location]




在Windows的用戶跟Mac(or Linux)用戶路徑斜線方向有差要小心
Windows的用戶:
dotnet sln add .\Web\Web.csproj

Mac(or Linux)用戶:
dotnet sln add ./Web/Web.csproj


Step4.
cd Web後
dotnet run Web.csproj
即可做建置與運行我們的.net5 web api專案
這時可以開瀏覽器輸入
https://localhost:5001/weatherforecast







就能把預設.net5 web api範本執行起來
你會好奇為何port我會知道要打5001? 而又要如何做port的變換設定
一來是因為cmd有輸出
二來是因為
在web api範本相對目錄下
.\Net5App1\Web\Properties
有一個launchSettings.json
裡面可以去做指定跟確認
預設分配port為 5001指定訪問的url

那5000那個輸入會沒辦法連線(以第一個為主)






Ref:
How to change the port number for Asp.Net core app?

How to add a Project (.csproj) to Solution (.sln) under a Solution Folder using dotnet CLI (command line)?



留言

這個網誌中的熱門文章

經得起原始碼資安弱點掃描的程式設計習慣培養(五)_Missing HSTS Header

經得起原始碼資安弱點掃描的程式設計習慣培養(三)_7.Cross Site Scripting(XSS)_Stored XSS_Reflected XSS All Clients

(2021年度)駕訓學科筆試準備題庫歸納分析_法規是非題