Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for loading MSBuild in a non-default ALC. #11111

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

teo-tsirpanis
Copy link
Contributor

Fixes #6794.

  • Instead of AssemblyLoadContext.Default we use the ALC that hosts MSBuild's own assemblies.
  • MSBuildLoadContext is created as unloadable if the ALC that hosts MSBuild's own assemblies is unloadable.
    • We don't do that always to avoid impacting performance and compatibility when not necessary, and plugin load contexts cannot be unloaded individually without more changes either way.

In most cases, including when running the MSBuild CLI, MSBuild is already loaded in the default ALC so this PR wouldn't change any behavior.

If MSBuild is loaded in a collectible ALC, its plugin ALCs will be collectible as well.
@teo-tsirpanis
Copy link
Contributor Author

Lucky PR number! 🍀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This class seems to be doing an AppDomain-specific thing, and all but one uses of it are guarded behind FEATURE_APPDOMAIN.

Does the class' functionality make sense for ALCs?

{
return assembly;
return MSBuildLoadContext.ThisAssemblyLoadContext.LoadFromAssemblyName(assemblyName);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this achieves the same goal in a much more straightforward way. And since we load a specific name in a specific context we don't need to patch the version.

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.

Remove assumption that MSBuild controls AssemblyLoadContext.Default
1 participant