Skip to content

Commit 8923b87

Browse files
rainersigwaldarturcic
authored andcommitted
Don't load MSBuild.Framework in GitLoaderContext
Unit tests were failing because they load MSBuild assemblies from the test output directory. Normally they're not available there, so GitLoaderContext doesn't load them. But in tests, they were there, and being loaded in both ALC.Default (from the main part of the test) and a GitLoaderContext created a type mismatch ``` MissingMethodException: Method not found: 'Microsoft.Build.Framework.ITaskItem[] GitVersion.MSBuildTask.Tasks.UpdateAssemblyInfo.get_CompileFiles()'. at GitVersion.MSBuildTask.GitVersionTaskExecutor.UpdateAssemblyInfo(UpdateAssemblyInfo task) at GitVersion.MSBuildTask.GitVersionTasks.<>c__DisplayClass1_0.<UpdateAssemblyInfo>b__0(IGitVersionTaskExecutor executor) in D:\a\1\s\src\GitVersionTask\GitVersionTasks.cs:line 15 at GitVersion.MSBuildTask.GitVersionTasks.ExecuteGitVersionTask[T](T task, Action`1 action) in D:\a\1\s\src\GitVersionTask\GitVersionTasks.cs:line 30 ``` That was happening because the loaded `UpdateAssemblyInfo.CompileFiles` was of type (`Microsoft.Build.Framework.ITaskItem[]` in the `GitLoaderContext`) while it was looking for (`Microsoft.Build.Framework.ITaskItem[]` in `AssemblyLoadContext.Default`).
1 parent a26b402 commit 8923b87

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/GitVersionTask.MsBuild/LibGit2Sharp/GitLoaderContext.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@ public sealed class GitLoaderContext : AssemblyLoadContext
1919

2020
protected override Assembly Load(AssemblyName assemblyName)
2121
{
22-
if (assemblyName.Name == entryPointAssembly.GetName().Name)
22+
string simpleName = assemblyName.Name;
23+
24+
if (simpleName == entryPointAssembly.GetName().Name)
2325
{
2426
return entryPointAssembly;
2527
}
2628

27-
var path = Path.Combine(Path.GetDirectoryName(typeof(GitLoaderContext).Assembly.Location), assemblyName.Name + ".dll");
29+
if (simpleName == "Microsoft.Build.Framework")
30+
{
31+
// Delegate loading MSBuild types up to an ALC that should already have them
32+
// once we've gotten this far
33+
return null;
34+
}
35+
36+
var path = Path.Combine(Path.GetDirectoryName(typeof(GitLoaderContext).Assembly.Location), simpleName + ".dll");
2837

2938
if (File.Exists(path))
3039
{

0 commit comments

Comments
 (0)