From ca28391b3886a1dd7d44b03496e5d90e37c09150 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Tue, 28 Jun 2016 13:29:17 -0700 Subject: [PATCH] Fix it for 'dotnet build' scenario --- .../CoreCLR/CorePsAssemblyLoadContext.cs | 27 +++++++++++++++++-- .../utils/ClrFacade.cs | 4 +-- src/powershell/Program.cs | 1 + 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CoreCLR/CorePsAssemblyLoadContext.cs b/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CoreCLR/CorePsAssemblyLoadContext.cs index abd822173..7b4f7f147 100644 --- a/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CoreCLR/CorePsAssemblyLoadContext.cs +++ b/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CoreCLR/CorePsAssemblyLoadContext.cs @@ -189,6 +189,7 @@ namespace System.Management.Automation if (useResolvingHandlerOnly) throw new NotSupportedException(UseResolvingEventHandlerOnly); + System.Console.WriteLine("== LC1 == Requesting: {0}", assemblyName.FullName); return Resolve(this, assemblyName); } @@ -246,6 +247,7 @@ namespace System.Management.Automation // In this case, return null so that other Resolving event handlers can kick in to resolve the request. if (!isAssemblyFileFound || !isAssemblyFileMatching) { + System.Console.WriteLine(" -- Return null"); return null; } @@ -256,6 +258,7 @@ namespace System.Management.Automation { // Add the loaded assembly to the cache AssemblyCache.TryAdd(assemblyName.Name, asmLoaded); + System.Console.WriteLine(" ++ Load succeed: {0}", asmLoaded.FullName); } } @@ -270,6 +273,7 @@ namespace System.Management.Automation internal Assembly LoadFrom(string assemblyPath) { ValidateAssemblyPath(assemblyPath, "assemblyPath"); + System.Console.WriteLine("*** LC1 *** LoadFrom {0}", assemblyPath); Assembly asmLoaded; AssemblyName assemblyName = GetAssemblyName(assemblyPath); @@ -300,6 +304,7 @@ namespace System.Management.Automation { probingPaths.Add(parentPath); } + System.Console.WriteLine(" ++ LoadFrom succeed: {0}", asmLoaded.FullName); } } @@ -436,10 +441,28 @@ namespace System.Management.Automation return coreClrTypeCatalog.Keys; } + /// + /// Set the profile optimization root on the approprite load context + /// + internal void SetProfileOptimizationRootImpl(string directoryPath) + { + if (this.useResolvingHandlerOnly) + activeLoadContext.SetProfileOptimizationRoot(directoryPath); + } + + /// + /// Start the profile optimization on the approprite load context + /// + internal void StartProfileOptimizationImpl(string profile) + { + if (this.useResolvingHandlerOnly) + activeLoadContext.StartProfileOptimization(profile); + } + #endregion Protected_Internal_Methods - + #region Private_Methods - + /// /// Handle the AssemblyLoad event /// diff --git a/src/System.Management.Automation/utils/ClrFacade.cs b/src/System.Management.Automation/utils/ClrFacade.cs index c866395de..16d085820 100644 --- a/src/System.Management.Automation/utils/ClrFacade.cs +++ b/src/System.Management.Automation/utils/ClrFacade.cs @@ -661,7 +661,7 @@ namespace System.Management.Automation internal static void SetProfileOptimizationRoot(string directoryPath) { #if CORECLR - System.Runtime.Loader.AssemblyLoadContext.Default.SetProfileOptimizationRoot(directoryPath); + PSAssemblyLoadContext.SetProfileOptimizationRootImpl(directoryPath); #else System.Runtime.ProfileOptimization.SetProfileRoot(directoryPath); #endif @@ -674,7 +674,7 @@ namespace System.Management.Automation internal static void StartProfileOptimization(string profile) { #if CORECLR - System.Runtime.Loader.AssemblyLoadContext.Default.StartProfileOptimization(profile); + PSAssemblyLoadContext.StartProfileOptimizationImpl(profile); #else System.Runtime.ProfileOptimization.StartProfile(profile); #endif diff --git a/src/powershell/Program.cs b/src/powershell/Program.cs index be8d1537b..01a958ec2 100644 --- a/src/powershell/Program.cs +++ b/src/powershell/Program.cs @@ -25,6 +25,7 @@ namespace Microsoft.PowerShell // Open PowerShell has to set the ALC here, since we don't own the native host string appBase = System.IO.Path.GetDirectoryName(typeof(ManagedPSEntry).GetTypeInfo().Assembly.Location); Console.WriteLine(" == APPBASE == {0}", appBase); + //Console.Read(); return (int)PowerShellAssemblyLoadContextInitializer. InitializeAndCallEntryMethod( appBase,