Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Probe .NET Framework dir for dependencies #1151

Merged
merged 1 commit into from
Jan 10, 2020
Merged
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
26 changes: 20 additions & 6 deletions src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public sealed class EditorServicesLoader : IDisposable
{
private const int Net461Version = 394254;

#if !CoreCLR
private static readonly string s_psesBaseDirPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
#endif

private static readonly string s_psesDependencyDirPath = Path.GetFullPath(
Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
Expand Down Expand Up @@ -72,7 +76,6 @@ public static EditorServicesLoader Create(

#if CoreCLR
// In .NET Core, we add an event here to redirect dependency loading to the new AssemblyLoadContext we load PSES' dependencies into

logger.Log(PsesLogLevel.Verbose, "Adding AssemblyResolve event handler for new AssemblyLoadContext dependency loading");

var psesLoadContext = new PsesLoadContext(s_psesDependencyDirPath);
Expand Down Expand Up @@ -123,14 +126,25 @@ public static EditorServicesLoader Create(
logger.Log(PsesLogLevel.Diagnostic, $"Assembly resolve event fired for {args.Name}");

var asmName = new AssemblyName(args.Name);
string asmPath = Path.Combine(s_psesDependencyDirPath, $"{asmName.Name}.dll");
if (!File.Exists(asmPath))
var dllName = $"{asmName.Name}.dll";

// First look for the required assembly in the .NET Framework DLL dir
string baseDirAsmPath = Path.Combine(s_psesBaseDirPath, dllName);
if (File.Exists(baseDirAsmPath))
{
return null;
logger.Log(PsesLogLevel.Diagnostic, $"Loading {args.Name} from PSES base dir into LoadFrom context");
return Assembly.LoadFrom(baseDirAsmPath);
}

// Then look in the shared .NET Standard directory
string asmPath = Path.Combine(s_psesDependencyDirPath, dllName);
if (File.Exists(asmPath))
{
logger.Log(PsesLogLevel.Diagnostic, $"Loading {args.Name} from PSES dependency dir into LoadFrom context");
return Assembly.LoadFrom(asmPath);
}

logger.Log(PsesLogLevel.Diagnostic, $"Loading {args.Name} from PSES dependency dir into LoadFrom context");
return Assembly.LoadFrom(asmPath);
return null;
};
#endif

Expand Down