Skip to content

Commit

Permalink
We don't have to hook assembly load now that we're not using MEF
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmalinowski committed Aug 30, 2023
1 parent d11bd4b commit c4a411d
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions src/Workspaces/Core/MSBuild.BuildHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
// See the LICENSE file in the project root for more information.

using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using StreamJsonRpc;
using System.CommandLine;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

#if NETCOREAPP
using System.Runtime.Loader;
#endif
using StreamJsonRpc;

namespace Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost;

Expand All @@ -35,25 +29,6 @@ internal static async Task Main(string[] args)

var logger = loggerFactory.CreateLogger(typeof(Program));

#if NETCOREAPP

// In the .NET Core case, the dependencies we want to dynamically load are not in our deps.json file, so we won't find them when MefHostServices tries to load them
// with Assembly.Load. To work around this, we'll use LoadFrom instead by hooking our AssemblyLoadContext Resolving.
var thisAssemblyDirectory = Path.GetDirectoryName(typeof(Program).Assembly.Location)!;
AssemblyLoadContext.Default.Resolving += (context, assemblyName) =>
{
try
{
return Assembly.LoadFrom(Path.Combine(thisAssemblyDirectory, assemblyName.Name! + ".dll"));
}
catch (Exception)
{
return null;
}
};

#endif

var messageHandler = new HeaderDelimitedMessageHandler(sendingStream: Console.OpenStandardOutput(), receivingStream: Console.OpenStandardInput(), new JsonMessageFormatter());

var jsonRpc = new JsonRpc(messageHandler)
Expand Down

0 comments on commit c4a411d

Please sign in to comment.