大家新年好,鼠年大吉。

今年過年比較怠惰,拖到初三才開始寫 Code。起了個迷你 Side-Project 計劃寫個網頁版「一二級保養檢核表」自用,最重要的目的是想熟悉 Razor Page。資料庫部分準備用 EF Core + SQLite,照著先前寫的 EF Core 筆記要產生資料表 Script,卻在跑 dotnet ef migrations add InitialCreate 時踩到小水坑,出現以下錯誤訊息:

因為找不到指定的命令或檔案,所以無法執行。
可能的原因包括:
  * 拼錯了內建 dotnet 命令。
  * 您預計要執行 .NET Core 程式,但 dotnet-ef 並不存在。
  * 您預計要執行全域工具,但在 PATH 上找不到此名稱且開頭為 dotnet 的可執行檔。
  
Could not execute because the specified command or file was not found.  
Possible reasons for this include:  
  * You misspelled a built-in dotnet command.  
  * You intended to execute a .NET Core program, but dotnet-ef does not exist.  
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

爬文後,很快找到答案,不意外地是版本相容問題。從 3.0 起,EF Core 命令列工具 (dotnet ef) 不再包含於 .NET Core SDK 裡,必須額外安裝。安裝指令為 dotnet tool install --global dotnet-ef,可愛的 EF 獨角獸就回來了:

查到文件後,有種似曾相識感,或許之前有讀過吧。只是當時無切身感受,匆匆用眼睛掃過純求心安,不痛不癢能留下記憶的只怕不到十分之一。說起來我註定還是勤能補拙的命,不紮紮實實寫成筆記,怎麼都沒法變成自己的,今年還是繼續認真寫筆記吧。

Tips of .NET Core 3.0 changes of .NET Core command line tools is removed from SDK.


Comments

Be the first to post a comment

Post a comment