Open
Description
Describe the bug
A project might want to constrain the SDK it builds with. This could be to pin the version or upgrade it. The SDK ignores this if it's launched from a different working directory. This could lead to folks thinking they're using an updated SDK but not.
To Reproduce
Place a global.json in a project folder that requires a specific SDK version. Run a dotnet build command on a project in that folder, but with a working directory from outside that folder.
A different SDK will be used than the one specified in global.json. No warnings will be raised.
See attached project.
Build from root, observe:
dotnet build project\project.csproj
MSBuild version 17.8.27+3ab07f0cf for .NET
Determining projects to restore...
All projects are up-to-date for restore.
project -> C:\scratch\testGlobalJson\project\bin\Debug\net8.0\project.dll
**SDK version: 8.0.116**
Build from project directory:
dotnet build project.csproj -tl:off
Determining projects to restore...
All projects are up-to-date for restore.
project -> C:\scratch\testGlobalJson\project\bin\Debug\net8.0\project.dll
**SDK version: 9.0.106**
Further technical details
- Include the output of
dotnet --info
- The IDE (VS / VS Code/ VS4Mac) you're running on, and its version