Coding ASP.NET Core Fluently with VSCode


  1. 說明
    1. 建立專案
    2. 加入 .gitignore
    3. 加入檔案
    4. 開啟檔案
    5. 執行專案並支援 Hot Reload

複習筆記,每當需要大量使用 VSCode 進行專案練習或者開發時,複習如何減少滑鼠操作,儘量透過鍵盤完成所有的程式碼編輯工作。

logo

說明

安裝 C# DevKit 支援更好的開發體驗。

建立專案

dotnet new console -o <ProjectName>
dotnet new webapp -o <ProjectName> 
dotnet new webapi -o <ProjectName>

藉由參數調整相關的專案建立:

dotnet new webapi -o <ProjectName> -minimal -f net7.0
dotnet new webapp -o <ProjectName> -au Windows

加入 .gitignore

使用 gitignore.io 所提供的 API 來產生 .gitignore 檔案,並且直接在 VSCode 專案當中一行完成:

(Invoke-WebRequest -Uri "https://www.toptal.com/developers/gitignore/api/aspnetcore").Content | Out-File -FilePath ".gitignore" -Force

同場加映,Curl 版本 😎:

curl -o .gitignore https://www.toptal.com/developers/gitignore/api/aspnetcore

加入檔案

Ctrl + ` 開啟 Terminal 或者使用 Ctrl + Shift + ` 新增 Terminal。

使用以下方式在專案中加入檔案:

code /Models/Person.cs
code /Controllers/PersonController.cs
code Dockerfile

開啟檔案

Ctrl + P 輸入檔案的關鍵字支援模糊搜尋。

執行專案並支援 Hot Reload

dotnet watch run