According to the Microsoft document, the SDK uses the latest installed version and this is an expected behavior:
The .NET CLI must choose an SDK version for every dotnet command. It
uses the latest SDK installed on the machine by default,
even if the project targets an earlier version of the .NET runtime.
So, it is not a real solution but changing the target framework of the project solves the issue.
Changing .Net version of the project is not a simple process so as a workaround, you can add a dummy word to the end of CLI command and it works:
dotnet watch run xyz
Another workaround, global.json below may help: select the .NET version to use
On rare occasions, you may need to use an earlier version of the SDK.
You specify that version in a global.json file. The “use latest”
policy means you only use global.json to specify a .NET SDK version
earlier than the latest installed version.
Create a global.json file and point it to the v6 SDK. global.json can be placed anywhere in the project file hierarchy.
{
"sdk": {
"version": "6.0.403"
}
}
You can find out current and installed SDK’s by running:
dotnet --info