[dev18.0.x] Fix SDK installation suggestion for already-installed versions - #9843
Closed
github-actions[bot] wants to merge 5 commits into
Closed
github-actions[bot] wants to merge 5 commits into
github-actions[bot] wants to merge 5 commits into
Conversation
Previously, the project retargeting handler would suggest installing an SDK version that was already installed on the system. This occurred because the check for installed SDKs was not properly implemented. Changes: - Add SdkInstallationService to detect globally installed .NET SDKs by querying the Windows registry for both 32-bit and 64-bit SDK installations - Add IRegistry abstraction and RegistryService implementation for testable registry access - Update ProjectRetargetHandler to check if the retarget SDK version is already installed before suggesting installation - Add IEnvironment abstraction and EnvironmentService for testable environment variable access - Add comprehensive unit tests for SdkInstallationService, RegistryService, and EnvironmentService - Simplify IRegistryMock test helper to use string-based keys instead of complex tuple structures - Fix JsonDocument.Parse to use ParseAsync for proper async/await pattern in ProjectRetargetHandler
Replace CLI-based SDK detection with direct Windows registry queries for improved
performance and reliability.
Key changes:
- Create IDotNetEnvironment service to centralize .NET environment queries
- Check installed SDK versions via registry (SOFTWARE\dotnet\Setup\InstalledVersions\{arch}\sdk)
- Detect .NET runtime versions via registry
- Locate dotnet.exe host path with registry fallback to Program Files
- Refactor SetupComponentRegistrationService to use IDotNetEnvironment instead of
NetCoreRuntimeVersionsRegistryReader
- Add ExceptionExtensions.IsCatchable() for safer exception handling
This eliminates the need to spawn dotnet.exe processes for SDK detection
* merged IEnvironmentHelper into IEnvironment * change IsSdkInstalledAsync to IsSdkInstalled * removed unneeded Is64BitOperatingSystem * Moved ExceptionExtensions to non-VS assembly, fixed namespace
drewnoakes
approved these changes
Oct 27, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #9834 to dev18.0.x
Requested in: %source_pr_url%#issuecomment-%trigger_comment_id%
/cc @phenning