[已解決] NuGet.Config 不是有效的 XML。解決方式

今天把某台電腦的 .NET 5 透過 Rider 的提示視窗自動「升級」到 .NET 6 之後,建立新專案要使用指令視窗安裝 NuGet 套件時發生下列錯誤:
    
PS C:\Users\ruyut\RiderProjects\SerialPortSentWinFormsApp1\SerialPortSentWinFormsApp1> dotnet add package System.IO.Ports --version 6.0.0
  正在判斷要還原的專案...
C:\Program Files\dotnet\sdk\6.0.302\NuGet.targets(564,5): error : NuGet.Config 不是有效的 XML。路徑: 'C:\Users\ruyut\AppData\Roaming\NuGet\NuGet.Config'。 [C:\Users\ruyut\RiderProjects\SerialPortSentWinFormsApp1\SerialPortSentWinFormsApp1\SerialPortSentWinFormsApp1.csproj]
C:\Program Files\dotnet\sdk\6.0.302\NuGet.targets(564,5): error :   '.', hexadecimal value 0x00, is an invalid character. Line 1, position 1. [C:\Users\ruyut\RiderProjects\SerialPortSentWinFormsApp1\SerialPortSentWinFormsApp1\SerialPortSentWinFormsApp1.csproj]
無法為專案 'C:\Users\ruyut\RiderProjects\SerialPortSentWinFormsApp1\SerialPortSentWinFormsApp1\SerialPortSentWinFormsApp1.csproj' 建立相依性關係圖檔案。無法新增套件參考。
    

原本想說是指令下錯了,於是開啟 NuGet 的介面,結果完全搜尋不到任何套件。然後也彈出同樣的錯誤提示。

解決方式

手忙腳亂的研究了半天,後來發現解決方式就是把錯誤訊息中提到的那個檔案刪掉就好了
    
C:\Users\ruyut\AppData\Roaming\NuGet\NuGet.Config
    

留言