Skip to content

Conversation

@github-actions
Copy link

Backport of #9834 to dev18.0.x

Requested in: %source_pr_url%#issuecomment-%trigger_comment_id%

/cc @phenning

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
@github-actions github-actions bot requested a review from a team as a code owner October 23, 2025 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants