Skip to content

Commit 1edc517

Browse files
rainersigwaldarturcic
authored andcommitted
Modify GitLoaderContext to load any assembly in the folder
When the entry-point task is loaded in an AssemblyLoadContext (as it is in MSBuild 16.5+ on .NET Core), the default ALC cannot load assemblies from next to the task location, so assemblies that are redistributed with the GitVersionTask package aren't automatically found. Extend the task's private ALC to support loading any assembly from the task's folder.
1 parent cbec4f8 commit 1edc517

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/GitVersionTask.MsBuild/LibGit2Sharp/GitLoaderContext.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@ namespace GitVersion.MSBuildTask.LibGit2Sharp
1111
{
1212
public sealed class GitLoaderContext : AssemblyLoadContext
1313
{
14-
private readonly string[] assemblies;
1514
public static GitLoaderContext Instance { get; private set; }
1615

17-
private GitLoaderContext(string[] assemblies) => this.assemblies = assemblies;
18-
19-
public static void Init(params string[] assemblies) => Instance = new GitLoaderContext(assemblies);
16+
public static void Init() => Instance = new GitLoaderContext();
2017

2118
protected override Assembly Load(AssemblyName assemblyName)
2219
{
23-
if (assemblies.Contains(assemblyName.Name))
20+
var path = Path.Combine(Path.GetDirectoryName(typeof(GitLoaderContext).Assembly.Location), assemblyName.Name + ".dll");
21+
22+
if (File.Exists(path))
2423
{
25-
var path = Path.Combine(Path.GetDirectoryName(typeof(GitLoaderContext).Assembly.Location), assemblyName.Name + ".dll");
2624
return LoadFromAssemblyPath(path);
2725
}
2826

src/GitVersionTask.MsBuild/TaskProxy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static TaskProxy()
1818
try
1919
{
2020
#if !NETFRAMEWORK
21-
GitLoaderContext.Init("GitVersionCore", "LibGit2Sharp");
21+
GitLoaderContext.Init();
2222
#endif
2323
LibGit2SharpLoader.LoadAssembly("GitVersionTask");
2424

0 commit comments

Comments
 (0)