2021年11月9日 星期二

安裝Visual Studio 2022 後Visual Studio 2019 專案無法載入 出現error: 無法開啟專案檔。找不到.NET SDK。請檢查是否安裝該項目,且在global.json中指定版本(如果有的話)是否安裝版本相符

昨天正式發表Visual Studio 2022 所以就來安裝 
結果我安裝Visual Studio 2022後 Visual Studio 2019 全部的專案都無法載入 出現
"error: 無法開啟專案檔。找不到.NET SDK。請檢查是否安裝該項目,且在global.json中指定版本(如果有的話)是否安裝版本相符。"
 如下圖
英文為
“The project file cannot be opened. Unable to locate the .NET SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.”
上網都查不到原因 google了很久
查到這個網站有解法
https://hamidmosalla.com/2021/03/13/unable-to-locate-the-net-sdk-the-reasons/

在環境變數裡面的Path 把C:\Program(x86)\donet\ 刪掉就可以正常開啟專案了
原因是安裝VS2022時多選擇安裝了.net 5 runtime

電腦按右鍵內容->進階->環境變數
環境變數->系統變數->Path->編輯

找到C:\Program Files(x86)\dotnet\ 按刪除