Skip to content

Commit

Permalink
Only look for .dll assemblies on Core
Browse files Browse the repository at this point in the history
.NET Core can sometimes use .exe extensions but in that case
the file is not a managed assembly any more and thus can't
be loaded by our plugin loader.
  • Loading branch information
rainersigwald committed Jul 27, 2021
1 parent d26cfbe commit ab9e654
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
33 changes: 15 additions & 18 deletions src/Shared/CoreCLRAssemblyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,23 @@ private Assembly TryResolveAssemblyFromPaths(AssemblyLoadContext context, Assemb
{
foreach (var searchPath in searchPaths)
{
foreach (var extension in MSBuildLoadContext.Extensions)
var candidatePath = Path.Combine(searchPath,
cultureSubfolder,
$"{assemblyName.Name}.dll");

if (IsAssemblyAlreadyLoaded(candidatePath) ||
!FileSystems.Default.FileExists(candidatePath))
{
var candidatePath = Path.Combine(searchPath,
cultureSubfolder,
$"{assemblyName.Name}.{extension}");

if (IsAssemblyAlreadyLoaded(candidatePath) ||
!FileSystems.Default.FileExists(candidatePath))
{
continue;
}

AssemblyName candidateAssemblyName = AssemblyLoadContext.GetAssemblyName(candidatePath);
if (candidateAssemblyName.Version != assemblyName.Version)
{
continue;
}

return LoadAndCache(context, candidatePath);
continue;
}

AssemblyName candidateAssemblyName = AssemblyLoadContext.GetAssemblyName(candidatePath);
if (candidateAssemblyName.Version != assemblyName.Version)
{
continue;
}

return LoadAndCache(context, candidatePath);
}
}

Expand Down
8 changes: 1 addition & 7 deletions src/Shared/MSBuildLoadContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ internal class MSBuildLoadContext : AssemblyLoadContext
"Microsoft.Build.Utilities.Core",
}.ToImmutableHashSet();

internal static readonly string[] Extensions = new[] { "dll", "exe" };


public MSBuildLoadContext(string assemblyPath)
: base($"MSBuild plugin {assemblyPath}")
{
Expand All @@ -56,11 +53,9 @@ public MSBuildLoadContext(string assemblyPath)
// bare search directory if that fails.
: new[] { assemblyName.CultureName, string.Empty })
{
foreach (var extension in Extensions)
{
var candidatePath = Path.Combine(_directory,
cultureSubfolder,
$"{assemblyName.Name}.{extension}");
$"{assemblyName.Name}.dll");

if (!FileSystems.Default.FileExists(candidatePath))
{
Expand All @@ -74,7 +69,6 @@ public MSBuildLoadContext(string assemblyPath)
}

return LoadFromAssemblyPath(candidatePath);
}
}

// If the Assembly is provided via a file path, the following rules are used to load the assembly:
Expand Down

0 comments on commit ab9e654

Please sign in to comment.