Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/MSBuildLocator/MSBuildLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;

#if NETCOREAPP
Expand Down Expand Up @@ -353,6 +354,29 @@ private static bool IsMSBuildAssembly(AssemblyName assemblyName)

return sb.ToString().Equals(MSBuildPublicKeyToken, StringComparison.OrdinalIgnoreCase);
}

#if NETCOREAPP
private static IntPtr HostFxrResolver(Assembly assembly, string libraryName)
{
if (libraryName != "hostfxr")
{
return IntPtr.Zero;
}

var path = Environment.GetEnvironmentVariable("HOSTFXR_PATH");
if (path == null)
{
return IntPtr.Zero;
}

if (!NativeLibrary.TryLoad(path, out var handle))
{
throw new Exception();
}

return handle;
}
#endif

private static IEnumerable<VisualStudioInstance> GetInstances(VisualStudioInstanceQueryOptions options)
{
Expand All @@ -368,6 +392,7 @@ private static IEnumerable<VisualStudioInstance> GetInstances(VisualStudioInstan
#endif

#if NETCOREAPP
AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly()).ResolvingUnmanagedDll += HostFxrResolver;
foreach (var dotnetSdk in DotNetSdkLocationHelper.GetInstances(options.WorkingDirectory))
yield return dotnetSdk;
#endif
Expand Down