Skip to content

Commit 62944c0

Browse files
Load ESCS in PSES's load context when in PSCore (#48)
1 parent db15601 commit 62944c0

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

EditorServicesCommandSuite.build.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ task AssertPowerShellCore {
6969
}
7070

7171
if ($Force.IsPresent) {
72-
choco install powershell-core --version 6.1.1 -y
72+
choco install powershell-core --version 6.2.3 -y
7373
} else {
74-
choco install powershell-core --verison 6.1.1
74+
choco install powershell-core --verison 6.2.3
7575
}
7676

7777
$script:pwsh = Get-Command $env:ProgramFiles/PowerShell/6/pwsh.exe @FailOnError

module/EditorServicesCommandSuite.psm1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@ Import-Module $PSScriptRoot/EditorServicesCommandSuite.RefactorCmdlets.cdxml
33
Update-FormatData -AppendPath $PSScriptRoot/EditorServicesCommandSuite.format.ps1xml
44

55
if ($null -ne $psEditor) {
6-
Add-Type -Path "$PSScriptRoot/EditorServicesCommandSuite.EditorServices.dll"
6+
if ($PSVersionTable.PSVersion.Major -ge 6) {
7+
$psesLoadContext = [System.Runtime.Loader.AssemblyLoadContext]::GetLoadContext(
8+
[Microsoft.PowerShell.EditorServices.Services.PowerShellContext.EditorObject].Assembly)
79

8-
$CommandSuite = [EditorServicesCommandSuite.EditorServices.Internal.CommandSuite]::GetCommandSuite(
10+
$assembly = $psesLoadContext.LoadFromAssemblyPath((
11+
Join-Path $PSScriptRoot -ChildPath 'EditorServicesCommandSuite.EditorServices.dll'))
12+
13+
$type = $assembly.GetType('EditorServicesCommandSuite.EditorServices.Internal.CommandSuite')
14+
} else {
15+
Add-Type -Path "$PSScriptRoot/EditorServicesCommandSuite.EditorServices.dll"
16+
$type = [EditorServicesCommandSuite.EditorServices.Internal.CommandSuite]
17+
}
18+
19+
$CommandSuite = $type::GetCommandSuite(
920
$psEditor,
1021
$ExecutionContext,
1122
$Host)

src/EditorServicesCommandSuite/EditorServicesCommandSuite.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<ItemGroup>
44
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
55
<PackageReference Include="System.Buffers" Version="4.4.0" />
6-
<PackageReference Include="System.Memory" Version="4.5.1" />
7-
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.14.0" />
6+
<PackageReference Include="System.Memory" Version="4.5.2" />
7+
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.14.1" />
8+
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.7.0" />
89
</ItemGroup>
910
</Project>

tools/AssertPSES.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[CmdletBinding()]
22
param(
33
[ValidateNotNull()]
4-
[string] $RequiredVersion = '2.0.0-preview.6'
4+
[string] $RequiredVersion = '2.0.0-preview.8'
55
)
66
begin {
77
Add-Type -AssemblyName System.IO.Compression
@@ -49,7 +49,7 @@ end {
4949
$oldSecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol
5050
try {
5151
[System.Net.ServicePointManager]::SecurityProtocol = 'Tls, Tls11, Tls12'
52-
$downloadUri = "https://github.com/PowerShell/PowerShellEditorServices/releases/download/v$version/PowerShellEditorServices.zip"
52+
$downloadUri = "https://github.com/PowerShell/PowerShellEditorServices/releases/download/$version/PowerShellEditorServices.zip"
5353
Invoke-WebRequest -UseBasicParsing -Uri $downloadUri -OutFile $psesFolder/PowerShellEditorServices.zip
5454
} finally {
5555
[System.Net.ServicePointManager]::SecurityProtocol = $oldSecurityProtocol

0 commit comments

Comments
 (0)