Skip to content

Conversation

@phenning
Copy link
Member

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

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
@phenning phenning requested a review from a team as a code owner October 21, 2025 22:45
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
Copy link
Member

@drewnoakes drewnoakes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nicely structured change. I like where this landed, and the test quality is chefs kiss :)

A few small comments but nothing major.

* merged IEnvironmentHelper into IEnvironment
* change IsSdkInstalledAsync to IsSdkInstalled
* removed unneeded Is64BitOperatingSystem
* Moved ExceptionExtensions to non-VS assembly, fixed namespace
@phenning phenning merged commit a525c6a into main Oct 23, 2025
5 checks passed
@phenning phenning deleted the phenning/checkforSdk branch October 23, 2025 15:20
@dotnet-policy-service dotnet-policy-service bot added this to the 18.1 milestone Oct 23, 2025
@phenning
Copy link
Member Author

/backport to dev18.0.x

@github-actions
Copy link

Started backporting to dev18.0.x: https://github.com/dotnet/project-system/actions/runs/18753332222

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.

4 participants