Skip to content

Commit a4b8dd0

Browse files
authored
Remove Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll (PowerShell#4868)
The code in `AssemblyLoadContext.dll` doesn't need to be in a separate DLL anymore. S.M.A.dll depends on `AssemblyLoadContext.dll`, so keeping that code out of S.M.A.dll doesn't help make S.M.A smaller size or less dependent. So the code in `AssemblyLoadContext.dll` is moved to `S.M.A.dll` and then we remove `AssemblyLoadContext.dll`. The changes are: - Move `CorePsAssemblyLoadContext.cs` to `src\S.M.A\CoreCLR\` - Update `CorePsAssemblyLoadContext.cs` to get the test took moved to `Utils.InternalTestHooks` and update tests - Update `build.psm1` and `.csproj` accrodingly - Update `pwrshcommon.cpp` to remove `AssemblyLoadContext.dll` from the TPA list. - `S.M.A.AssemblyExtensions` is removed as `PackageManagement` has finished their move to .NET Core 2.0. (I will work with Bryan to get the latest version uploaded to powershell-core)
1 parent 2639cd8 commit a4b8dd0

File tree

13 files changed

+47
-208
lines changed

13 files changed

+47
-208
lines changed

PowerShell-Win.sln

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.PowerShell.Comman
1111
EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.PowerShell.CoreCLR.Eventing", "src\Microsoft.PowerShell.CoreCLR.Eventing\Microsoft.PowerShell.CoreCLR.Eventing.csproj", "{981D3972-343D-4E17-935B-037E1C622771}"
1313
EndProject
14-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.PowerShell.CoreCLR.AssemblyLoadContext", "src\Microsoft.PowerShell.CoreCLR.AssemblyLoadContext\Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.csproj", "{377D8A33-22F2-43ED-9E81-FCB56874A48C}"
15-
EndProject
1614
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.PowerShell.ConsoleHost", "src\Microsoft.PowerShell.ConsoleHost\Microsoft.PowerShell.ConsoleHost.csproj", "{8FFE645D-F0C9-4220-9A88-83062ED211D2}"
1715
EndProject
1816
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.PowerShell.Commands.Management", "src\Microsoft.PowerShell.Commands.Management\Microsoft.PowerShell.Commands.Management.csproj", "{FCE53A5E-5FAC-48BE-BAD8-2110040B5C2E}"
@@ -71,14 +69,6 @@ Global
7169
{981D3972-343D-4E17-935B-037E1C622771}.Linux|Any CPU.Build.0 = Linux|Any CPU
7270
{981D3972-343D-4E17-935B-037E1C622771}.Release|Any CPU.ActiveCfg = Release|Any CPU
7371
{981D3972-343D-4E17-935B-037E1C622771}.Release|Any CPU.Build.0 = Release|Any CPU
74-
{377D8A33-22F2-43ED-9E81-FCB56874A48C}.CodeCoverage|Any CPU.ActiveCfg = CodeCoverage|Any CPU
75-
{377D8A33-22F2-43ED-9E81-FCB56874A48C}.CodeCoverage|Any CPU.Build.0 = CodeCoverage|Any CPU
76-
{377D8A33-22F2-43ED-9E81-FCB56874A48C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
77-
{377D8A33-22F2-43ED-9E81-FCB56874A48C}.Debug|Any CPU.Build.0 = Debug|Any CPU
78-
{377D8A33-22F2-43ED-9E81-FCB56874A48C}.Linux|Any CPU.ActiveCfg = Linux|Any CPU
79-
{377D8A33-22F2-43ED-9E81-FCB56874A48C}.Linux|Any CPU.Build.0 = Linux|Any CPU
80-
{377D8A33-22F2-43ED-9E81-FCB56874A48C}.Release|Any CPU.ActiveCfg = Release|Any CPU
81-
{377D8A33-22F2-43ED-9E81-FCB56874A48C}.Release|Any CPU.Build.0 = Release|Any CPU
8272
{8FFE645D-F0C9-4220-9A88-83062ED211D2}.CodeCoverage|Any CPU.ActiveCfg = CodeCoverage|Any CPU
8373
{8FFE645D-F0C9-4220-9A88-83062ED211D2}.CodeCoverage|Any CPU.Build.0 = CodeCoverage|Any CPU
8474
{8FFE645D-F0C9-4220-9A88-83062ED211D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU

build.psm1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ Fix steps:
488488
}
489489

490490
# handle TypeGen
491-
if ($TypeGen -or -not (Test-Path "$PSScriptRoot/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CorePsTypeCatalog.cs")) {
491+
if ($TypeGen -or -not (Test-Path "$PSScriptRoot/src/System.Management.Automation/CoreCLR/CorePsTypeCatalog.cs")) {
492492
log "Run TypeGen (generating CorePsTypeCatalog.cs)"
493493
Start-TypeGen
494494
}
@@ -1529,7 +1529,6 @@ function Publish-NuGetFeed
15291529
'Microsoft.PowerShell.ConsoleHost',
15301530
'Microsoft.PowerShell.Security',
15311531
'System.Management.Automation',
1532-
'Microsoft.PowerShell.CoreCLR.AssemblyLoadContext',
15331532
'Microsoft.PowerShell.CoreCLR.Eventing',
15341533
'Microsoft.WSMan.Management',
15351534
'Microsoft.WSMan.Runtime',
@@ -1635,7 +1634,7 @@ function Start-TypeGen
16351634

16361635
Push-Location "$PSScriptRoot/src/TypeCatalogGen"
16371636
try {
1638-
dotnet run ../Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CorePsTypeCatalog.cs powershell.inc
1637+
dotnet run ../System.Management.Automation/CoreCLR/CorePsTypeCatalog.cs powershell.inc
16391638
} finally {
16401639
Pop-Location
16411640
}
@@ -2074,7 +2073,6 @@ function Start-CrossGen {
20742073
"Microsoft.PowerShell.Commands.Utility.dll",
20752074
"Microsoft.PowerShell.Commands.Management.dll",
20762075
"Microsoft.PowerShell.Security.dll",
2077-
"Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll",
20782076
"Microsoft.PowerShell.CoreCLR.Eventing.dll",
20792077
"Microsoft.PowerShell.ConsoleHost.dll",
20802078
"Microsoft.PowerShell.PSReadLine.dll",

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

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.csproj

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 39 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ private Assembly Resolve(AssemblyLoadContext loadContext, AssemblyName assemblyN
267267
{
268268
#if !UNIX
269269
//Try loading from GAC
270-
if(!TryFindInGAC(assemblyName, out asmFilePath))
270+
if (!TryFindInGAC(assemblyName, out asmFilePath))
271271
{
272272
return null;
273273
}
@@ -295,53 +295,55 @@ private Assembly Resolve(AssemblyLoadContext loadContext, AssemblyName assemblyN
295295
// If there are multiple version of the assembly, load the latest.
296296
private bool TryFindInGAC(AssemblyName assemblyName, out string assemblyFilePath)
297297
{
298-
bool assemblyFound = false;
299298
assemblyFilePath = null;
299+
if (Internal.InternalTestHooks.DisableGACLoading)
300+
{
301+
return false;
302+
}
303+
304+
bool assemblyFound = false;
300305
char dirSeparator = IO.Path.DirectorySeparatorChar;
301306

302-
if (PowerShellAssemblyLoadContextTestHooks.AllowGACLoading)
307+
if (String.IsNullOrEmpty(_winDir))
303308
{
304-
if(String.IsNullOrEmpty(_winDir))
305-
{
306-
//cache value of '_winDir' folder in member variable.
307-
_winDir = Environment.GetEnvironmentVariable("winDir");
308-
}
309+
//cache value of '_winDir' folder in member variable.
310+
_winDir = Environment.GetEnvironmentVariable("winDir");
311+
}
309312

310-
if (String.IsNullOrEmpty(_gacPathMSIL))
311-
{
312-
//cache value of '_gacPathMSIL' folder in member variable.
313-
_gacPathMSIL = $"{_winDir}{dirSeparator}Microsoft.NET{dirSeparator}assembly{dirSeparator}GAC_MSIL";
314-
}
313+
if (String.IsNullOrEmpty(_gacPathMSIL))
314+
{
315+
//cache value of '_gacPathMSIL' folder in member variable.
316+
_gacPathMSIL = $"{_winDir}{dirSeparator}Microsoft.NET{dirSeparator}assembly{dirSeparator}GAC_MSIL";
317+
}
315318

316-
assemblyFound = FindInGac(_gacPathMSIL, assemblyName, out assemblyFilePath);
319+
assemblyFound = FindInGac(_gacPathMSIL, assemblyName, out assemblyFilePath);
317320

318-
if(!assemblyFound)
319-
{
320-
string gacBitnessAwarePath = null;
321+
if (!assemblyFound)
322+
{
323+
string gacBitnessAwarePath = null;
321324

322-
if(Environment.Is64BitProcess)
325+
if (Environment.Is64BitProcess)
326+
{
327+
if (String.IsNullOrEmpty(_gacPath64))
323328
{
324-
if(String.IsNullOrEmpty(_gacPath64))
325-
{
326-
//cache value of '_gacPath64' folder in member variable.
327-
_gacPath64 = $"{_winDir}{dirSeparator}Microsoft.NET{dirSeparator}assembly{dirSeparator}GAC_64";
328-
}
329-
330-
gacBitnessAwarePath = _gacPath64;
329+
//cache value of '_gacPath64' folder in member variable.
330+
_gacPath64 = $"{_winDir}{dirSeparator}Microsoft.NET{dirSeparator}assembly{dirSeparator}GAC_64";
331331
}
332-
else
333-
{
334-
if(String.IsNullOrEmpty(_gacPath32))
335-
{
336-
//cache value of '_gacPath32' folder in member variable.
337-
_gacPath32 = $"{_winDir}{dirSeparator}Microsoft.NET{dirSeparator}assembly{dirSeparator}GAC_32";
338-
}
339332

340-
gacBitnessAwarePath = _gacPath32;
333+
gacBitnessAwarePath = _gacPath64;
334+
}
335+
else
336+
{
337+
if (String.IsNullOrEmpty(_gacPath32))
338+
{
339+
//cache value of '_gacPath32' folder in member variable.
340+
_gacPath32 = $"{_winDir}{dirSeparator}Microsoft.NET{dirSeparator}assembly{dirSeparator}GAC_32";
341341
}
342342

343-
assemblyFound = FindInGac(gacBitnessAwarePath, assemblyName, out assemblyFilePath);
343+
gacBitnessAwarePath = _gacPath32;
344344
}
345+
346+
assemblyFound = FindInGac(gacBitnessAwarePath, assemblyName, out assemblyFilePath);
345347
}
346348

347349
return assemblyFound;
@@ -356,17 +358,17 @@ private bool FindInGac(string gacRoot, AssemblyName assemblyName, out string ass
356358
char dirSeparator = IO.Path.DirectorySeparatorChar;
357359
string tempAssemblyDirPath = $"{gacRoot}{dirSeparator}{assemblyName.Name}";
358360

359-
if(Directory.Exists(tempAssemblyDirPath))
361+
if (Directory.Exists(tempAssemblyDirPath))
360362
{
361363
//Enumerate all directories, sort by name and select the last. This selects the latest version.
362364
var chosenVersionDirectory = Directory.GetDirectories(tempAssemblyDirPath).OrderBy(d => d).LastOrDefault();
363365

364-
if(!String.IsNullOrEmpty(chosenVersionDirectory))
366+
if (!String.IsNullOrEmpty(chosenVersionDirectory))
365367
{
366368
//Select first or default as the directory will contain only one assembly. If nothing then default is null;
367369
var foundAssemblyPath = Directory.GetFiles(chosenVersionDirectory, $"{assemblyName.Name}*").FirstOrDefault();
368370

369-
if(!String.IsNullOrEmpty(foundAssemblyPath))
371+
if (!String.IsNullOrEmpty(foundAssemblyPath))
370372
{
371373
AssemblyName asmNameFound = AssemblyLoadContext.GetAssemblyName(foundAssemblyPath);
372374
if (IsAssemblyMatching(assemblyName, asmNameFound))
@@ -515,24 +517,6 @@ public static void SetPowerShellAssemblyLoadContext([MarshalAs(UnmanagedType.LPW
515517
PowerShellAssemblyLoadContext.InitializeSingleton(basePaths);
516518
}
517519
}
518-
519-
/// <summary>
520-
/// Test hooks for PowershellAssemblyLoadContext
521-
/// </summary>
522-
public static class PowerShellAssemblyLoadContextTestHooks
523-
{
524-
internal static bool AllowGACLoading = true;
525-
526-
/// <summary>This member is used for internal test purposes.</summary>
527-
public static void SetTestHook(string property, bool value)
528-
{
529-
var fieldInfo = typeof(PowerShellAssemblyLoadContextTestHooks).GetField(property, BindingFlags.Static | BindingFlags.NonPublic);
530-
if (fieldInfo != null)
531-
{
532-
fieldInfo.SetValue(null, value);
533-
}
534-
}
535-
}
536520
}
537521

538522
#endif

src/System.Management.Automation/CoreCLR/CorePsExtensions.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/System.Management.Automation/System.Management.Automation.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<ProjectReference Include="..\Microsoft.PowerShell.CoreCLR.AssemblyLoadContext\Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.csproj" />
1110
<ProjectReference Include="..\Microsoft.PowerShell.CoreCLR.Eventing\Microsoft.PowerShell.CoreCLR.Eventing.csproj" />
1211
<PackageReference Include="Microsoft.Win32.Registry.AccessControl" Version="4.4.0" />
1312
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />

src/System.Management.Automation/engine/Utils.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,7 @@ public static class InternalTestHooks
14701470
internal static bool IgnoreScriptBlockCache;
14711471
// Simulate 'System.Diagnostics.Stopwatch.IsHighResolution is false' to test Get-Uptime throw
14721472
internal static bool StopwatchIsNotHighResolution;
1473+
internal static bool DisableGACLoading;
14731474

14741475
/// <summary>This member is used for internal test purposes.</summary>
14751476
public static void SetTestHook(string property, bool value)

0 commit comments

Comments
 (0)