Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Shared/MSBuildLoadContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ public MSBuildLoadContext(string assemblyPath)
// If the Assembly is provided via a file path, the following rules are used to load the assembly:
// - the assembly from the user specified path is loaded, if it exists, into the custom ALC, or
// - if the simple name of the assembly exists in the same folder as msbuild.exe, then that assembly gets loaded
// into the default ALC (so it's shared with other uses).
// into the default ALC (so it's shared with other uses), or into the custom ALC if we are not running on
// MSBuild.exe (because it might interfere with the app's own dependencies).
var assemblyNameInExecutableDirectory = Path.Combine(BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory,
$"{assemblyName.Name}.dll");

if (FileSystems.Default.FileExists(assemblyNameInExecutableDirectory))
{
return AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyNameInExecutableDirectory);
AssemblyLoadContext targetAlc = BuildEnvironmentHelper.Instance.RunningInMSBuildExe ? Default : this;
return targetAlc.LoadFromAssemblyPath(assemblyNameInExecutableDirectory);
}

return null;
Expand Down
Loading