Skip to content

Commit ca28391

Browse files
daxian-dbwandyleejordan
authored andcommitted
Fix it for 'dotnet build' scenario
1 parent 66dcd00 commit ca28391

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CoreCLR/CorePsAssemblyLoadContext.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ protected override Assembly Load(AssemblyName assemblyName)
189189
if (useResolvingHandlerOnly)
190190
throw new NotSupportedException(UseResolvingEventHandlerOnly);
191191

192+
System.Console.WriteLine("== LC1 == Requesting: {0}", assemblyName.FullName);
192193
return Resolve(this, assemblyName);
193194
}
194195

@@ -246,6 +247,7 @@ private Assembly Resolve(AssemblyLoadContext loadContext, AssemblyName assemblyN
246247
// In this case, return null so that other Resolving event handlers can kick in to resolve the request.
247248
if (!isAssemblyFileFound || !isAssemblyFileMatching)
248249
{
250+
System.Console.WriteLine(" -- Return null");
249251
return null;
250252
}
251253

@@ -256,6 +258,7 @@ private Assembly Resolve(AssemblyLoadContext loadContext, AssemblyName assemblyN
256258
{
257259
// Add the loaded assembly to the cache
258260
AssemblyCache.TryAdd(assemblyName.Name, asmLoaded);
261+
System.Console.WriteLine(" ++ Load succeed: {0}", asmLoaded.FullName);
259262
}
260263
}
261264

@@ -270,6 +273,7 @@ private Assembly Resolve(AssemblyLoadContext loadContext, AssemblyName assemblyN
270273
internal Assembly LoadFrom(string assemblyPath)
271274
{
272275
ValidateAssemblyPath(assemblyPath, "assemblyPath");
276+
System.Console.WriteLine("*** LC1 *** LoadFrom {0}", assemblyPath);
273277

274278
Assembly asmLoaded;
275279
AssemblyName assemblyName = GetAssemblyName(assemblyPath);
@@ -300,6 +304,7 @@ internal Assembly LoadFrom(string assemblyPath)
300304
{
301305
probingPaths.Add(parentPath);
302306
}
307+
System.Console.WriteLine(" ++ LoadFrom succeed: {0}", asmLoaded.FullName);
303308
}
304309
}
305310

@@ -436,10 +441,28 @@ internal IEnumerable<string> GetAvailableDotNetTypes()
436441
return coreClrTypeCatalog.Keys;
437442
}
438443

444+
/// <summary>
445+
/// Set the profile optimization root on the approprite load context
446+
/// </summary>
447+
internal void SetProfileOptimizationRootImpl(string directoryPath)
448+
{
449+
if (this.useResolvingHandlerOnly)
450+
activeLoadContext.SetProfileOptimizationRoot(directoryPath);
451+
}
452+
453+
/// <summary>
454+
/// Start the profile optimization on the approprite load context
455+
/// </summary>
456+
internal void StartProfileOptimizationImpl(string profile)
457+
{
458+
if (this.useResolvingHandlerOnly)
459+
activeLoadContext.StartProfileOptimization(profile);
460+
}
461+
439462
#endregion Protected_Internal_Methods
440-
463+
441464
#region Private_Methods
442-
465+
443466
/// <summary>
444467
/// Handle the AssemblyLoad event
445468
/// </summary>

src/System.Management.Automation/utils/ClrFacade.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ internal static void SetSafeWaitHandle(WaitHandle waitHandle, SafeWaitHandle val
661661
internal static void SetProfileOptimizationRoot(string directoryPath)
662662
{
663663
#if CORECLR
664-
System.Runtime.Loader.AssemblyLoadContext.Default.SetProfileOptimizationRoot(directoryPath);
664+
PSAssemblyLoadContext.SetProfileOptimizationRootImpl(directoryPath);
665665
#else
666666
System.Runtime.ProfileOptimization.SetProfileRoot(directoryPath);
667667
#endif
@@ -674,7 +674,7 @@ internal static void SetProfileOptimizationRoot(string directoryPath)
674674
internal static void StartProfileOptimization(string profile)
675675
{
676676
#if CORECLR
677-
System.Runtime.Loader.AssemblyLoadContext.Default.StartProfileOptimization(profile);
677+
PSAssemblyLoadContext.StartProfileOptimizationImpl(profile);
678678
#else
679679
System.Runtime.ProfileOptimization.StartProfile(profile);
680680
#endif

src/powershell/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static int Main(string[] args)
2525
// Open PowerShell has to set the ALC here, since we don't own the native host
2626
string appBase = System.IO.Path.GetDirectoryName(typeof(ManagedPSEntry).GetTypeInfo().Assembly.Location);
2727
Console.WriteLine(" == APPBASE == {0}", appBase);
28+
//Console.Read();
2829
return (int)PowerShellAssemblyLoadContextInitializer.
2930
InitializeAndCallEntryMethod(
3031
appBase,

0 commit comments

Comments
 (0)