Allow the dotnet CLI host to ignore global.json during SDK resolution
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
The commands available to the dotnet CLI are dependent on the resolved SDK. There are some commands such as `dnx` which should function regardless of what SDK is pinned in the global.json. This has become a problem for running the Roslyn LSP in the Copilot CLI as it uses `dotnet dnx` to launch the LSP, but this will fail if the folder being run against has pinned to .NET 9 or lower.
Proposal:
The dotnet CLI host should support either a command-line options(`--ignore-global-json`) or an environment variable (`DOTNET_IGNORE_GLOBAL_JSON`) so that the host resolves the SDK as if no global.json is present. When the flag is set we can pass `nullptr` or empty string as the working directory when invoking `hostfxr_reslve_sdk2` ([see code](https://github.com/dotnet/runtime/blob/d2161b7a600fd34eca6f6801519314c852666b1d/src/native/corehost/fxr/hostfxr.cpp#L214)).
If we go the environment variable route, we may want to think about whether we should clear the variable before handing execution to the CLI command being executed. I can imagine a dotnet tool might get executed that then invokes the dotnet CLI and expects that the global.json is included in resolution.
Contributor guide
Assessment
This issue has not been assessed yet.