Try   HackMD

「跨 Mac|Linux|Windows 三大平台 .NET Core 開發實作」閱讀筆記

已經習慣 Visual Studio 2017/2019 的視窗介面操作
看這本書可以習慣一下命令模式來體驗 .NET Core 的使用

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
學習目標

  • 學會利用 dotnet 指令來建立與發佈專案
  • 學會利用 Visual Studio Core 來建立或編輯、發佈 .NET Core 專案

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
dotnet 指令

  • dotnet 指令是跨平台的
    假設在 windows 學會了 dotnet 指令建立專案
    你就能在 Mac、Linux等平台建立 .NET Core 專案

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
dotnet new

  • dotnet new 根據後面所帶入的 Templates 的範例 Short Name 短名
    建立新的專案

注意 dotnet new 出來的專案都沒有 sln 檔

dotnet new -all
  • 可以列出所有的範本清單
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 指定用 F# 語言來建立 console 專案
dotnet new console -lang f#
  • 新增 .NET Core 3.1 且沒有設定身分驗證的 ASP.NET Core C# MVC 應用程式
dotnet new mvc -au none -f netcoreapp3.1
  • 新增 .NET Core 3.1 的 xUnit 應用程式
dotnet new xunit -f netcoreapp3.1

or

dotnet new xunit --framework netcoreapp3.1

要確認一下 dotnet 的安裝版本
會限制 -f 後面的 netcoreapp版本號
且這兩個指令結果是一樣的

  • 列出關鍵字 view 的所有範本
dotnet new view -l

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

會包含 Template 與 Short Name 欄位

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
dotnet restore

  • 還原專案依賴項?字面上看起來我還沒辦法解釋得很好
  • 查看 dotnet restore 的指令說明
dotnet restore -h

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • 還原目前目錄中專案的依賴項
dotnet restore
  • 還原指定目錄中專案的依賴項
dotnet restore ~/projects/coreapp/coreapp.csproj

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
dotnet run

  • 執行目前目錄的程式碼
    其實等同於執行
dotnet run

or

dotnet myapp.dll
  • 指定執行特定目錄的專案檔(不指定則是目前目錄)
dotnet run --project ./console/console.csproj

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
dotnet build

  • 編譯專案執行檔與所有相依項
  • 編譯目前目錄專案
dotnet build
  • 編譯目前目錄專案並輸出到 .\mydll
dotnet build --output .\mydll

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
dotnet test

  • 單元測試
    暫略過

dotnet pack

  • 建立 NuGet 套件
    暫略過

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
dotnet publish

  • 封裝應用程式與所有依賴項道資料夾中,準備發佈
  • 發佈目前的目錄
dotnet publish

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • 發佈指定目錄專案
dotnet publish ./console/console.csproj

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
dotnet 指令實戰

  • 用一個實例,串起剛剛所學的指令
    馬上獲得「未到班 dotnet 指令大師」稱號

暫略過

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
VS Code 開發 .NET Core

  • 用 VS Code 開啟目前目錄的專案
code .
  • 執行後在執行目錄的 .vscode 目錄裡會新增 lunch.json 與 task.json 這兩個檔案
  • task.json 用於設定執行那些指令來建置專案
{ "version": "2.0.0", "tasks": [ { "label": "build", "command": "dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/console.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile" }, { "label": "publish", "command": "dotnet", "type": "process", "args": [ "publish", "${workspaceFolder}/console.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile" }, { "label": "watch", "command": "dotnet", "type": "process", "args": [ "watch", "run", "${workspaceFolder}/console.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile" } ] }
  • launch.json 設定要指定的偵錯器的類型,以及程式應該在什麼偵錯下執行。
{ // 使用 IntelliSense 以得知可用的屬性。 // 暫留以檢視現有屬性的描述。 // 如需詳細資訊,請瀏覽: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": ".NET Core Attach", "type": "coreclr", "request": "attach", "processId": "${command:pickProcess}" }, { "name": ".NET Core Launch (console)", "type": "coreclr", "request": "launch", "preLaunchTask": "build", "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/console.dll", "args": [], "cwd": "${workspaceFolder}", "console": "internalConsole", "stopAtEntry": false }, { "name": ".NET Core Attach", "type": "coreclr", "request": "attach", "processId": "${command:pickProcess}" } ] }

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
VS2017 開發 .NET Core

按一下按鈕以下載最新版的 Visual Studio 2017

  • 新增 .NET Core 專案
tags: 筆記 .NET Core