Skip to content

Add fallback behavior for Microsoft.DotNet.MsBuildSdkResolver loading in external API scenarios - #12703

Merged
SimaTian merged 8 commits into
dotnet:mainfrom
huulinhnguyen-dev:dev/huulinhnguyen/fail-to-resolve-MsBuildSdkResolver
Dec 1, 2025
Merged

SimaTian merged 8 commits into
dotnet:mainfrom
huulinhnguyen-dev:dev/huulinhnguyen/fail-to-resolve-MsBuildSdkResolver

Conversation

@huulinhnguyen-dev

Copy link
Copy Markdown
Contributor

Fixes #
Fix the issue: Could not load file or assembly Microsoft.DotNet.MsBuildSdkResolver #12578

Context

External API users were experiencing failures when loading Microsoft.DotNet.MSBuildSdkResolver because Assembly.Load with CodeBase was failing. This caused SDK resolution to fail for external tools and applications.

Changes Made

  • Modified LoadResolverAssembly in SdkResolverLoader to add fallback behavior for external API users
  • External API users now fallback from Assembly.Load to Assembly.LoadFrom when Assembly.Load fails
  • Added unit tests to verify both fallback and no-fallback scenarios

Testing

  • Added LoadResolverAssembly_MSBuildSdkResolver_ExternalAPIUser_FallbackSucceeds test to verify external API users get successful fallback
  • Added LoadResolverAssembly_MSBuildSdkResolver_VisualStudioUser_NoFallback test to verify VS users don't get fallback
  • Tests use TestableSdkResolverLoader to control RunningInVisualStudio environment and test path

Notes

This change improves compatibility for external API users while maintaining the existing behavior for Visual Studio users. The fallback ensures that SDK resolution works in more scenarios without breaking VS functionality.

@huulinhnguyen-dev
huulinhnguyen-dev force-pushed the dev/huulinhnguyen/fail-to-resolve-MsBuildSdkResolver branch from d09e1d3 to 50d9905 Compare November 4, 2025 06:38
@huulinhnguyen-dev
huulinhnguyen-dev force-pushed the dev/huulinhnguyen/fail-to-resolve-MsBuildSdkResolver branch from 6d951d8 to 8a4c5dd Compare November 5, 2025 05:32
@huulinhnguyen-dev
huulinhnguyen-dev force-pushed the dev/huulinhnguyen/fail-to-resolve-MsBuildSdkResolver branch from a3ff673 to ec2dca6 Compare November 5, 2025 08:06
@SimaTian

Copy link
Copy Markdown
Contributor

As you can see here: https://github.com/dotnet/msbuild/pull/12822/files, the test still passes even without your change. Is there anything we can do to make the test work correctly in the un-fixed scenario please?

@SimaTian

SimaTian commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

Test validated here, I made an error.

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