I have a project that is using net6
as the target framework. I recently installed .net core 7 SDK on my PC. After that, when I use dotnet watch run
I get a strange error:
Unhandled exception.
System.IO.FileNotFoundException:
Could not load file or assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
The system cannot find the file specified.
.....
As the error suggests it is looking for .net 7 dlls in my project, while my project is targeting .net 6!
For a quick hack, I added a global.json
in the root of project to explicitly using .net 6 SDK to build my project. However, I want a proper solution, and to know the reason behind this error.
Please note that I only experience this issue with dotnet watch run
. I.e., other cases like dotnet build
, dotnet run
, dotnet publish
are all fine!