If the version from Visual Studio/Visual Studio Code does not match the latest installed .NET SDK please verify the path that is used by the application to load the SDK.
Control Panel -> Edit system environment variables -> Advanced Tab -> Environment Variables.
Check in System variables that MSBuildSDKsPath is pointing to your needed SDK.