From 361bcdb1c2fae338c5fff07360d387848248e242 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Thu, 11 Jun 2020 23:03:13 +0200 Subject: [PATCH] Work around a bug in .NET SDK 3.1 --- dotnet-rpm/PackagingRunner.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/dotnet-rpm/PackagingRunner.cs b/dotnet-rpm/PackagingRunner.cs index 4d303d7..0dc6cb8 100644 --- a/dotnet-rpm/PackagingRunner.cs +++ b/dotnet-rpm/PackagingRunner.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; +using System.Runtime.Loader; using System.Text; using ConsoleLogger = Microsoft.Build.Logging.ConsoleLogger; using IMSBuildLogger = Microsoft.Build.Framework.ILogger; @@ -22,7 +23,19 @@ namespace Dotnet.Packaging public PackagingRunner(string outputName, string msbuildTarget, string commandName) { - MSBuildLocator.RegisterDefaults(); + var instance = MSBuildLocator.RegisterDefaults(); + + // Workaround for https://github.com/microsoft/MSBuildLocator/issues/86 + AssemblyLoadContext.Default.Resolving += (assemblyLoadContext, assemblyName) => + { + var path = Path.Combine(instance.MSBuildPath, assemblyName.Name + ".dll"); + if (File.Exists(path)) + { + return assemblyLoadContext.LoadFromAssemblyPath(path); + } + + return null; + }; this.outputName = outputName; this.msbuildTarget = msbuildTarget;