Skip to content

Commit fd06514

Browse files
committed
Migrate to netstandard2.0 and PSStandard (PowerShell#741)
* Move PSES builds to netstandard and use PSStandard APIs * Add shim modules for Windows PowerShell and PowerShell Core 6.0 * Migrate tests to run on .NET Core and on *nix * Make build file more declarative * Use latest xunit * Exclude host integration tests * Clean out csproj files * Fix up Travis build * Retire compatibility APIs for PowerShell v3/4 * Introduce test hook for using InitialSessionState.CreateDefault2() when running on PowerShell Core SDK * Fix session details gathering in nested prompts To create a nested PowerShell instance you can't set the runspace because the target runspace is assumed to be the runspace in TLS.
1 parent 4cc0ea9 commit fd06514

File tree

71 files changed

+809
-850
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+809
-850
lines changed

.travis.yml

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ language: cpp
33
git:
44
depth: 1000
55

6-
os:
7-
- linux
8-
- osx
9-
sudo: required
10-
dist: trusty
11-
osx_image: xcode8.3
6+
matrix:
7+
include:
8+
- os: linux
9+
dist: trusty
10+
sudo: required
11+
- os: osx
12+
osx_image: xcode9.4
1213

1314
before_install:
1415
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then

PowerShellEditorServices.Common.props

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<VersionPrefix>1.10.3</VersionPrefix>
3+
<VersionPrefix>2.0.0</VersionPrefix>
44
<Company>Microsoft</Company>
55
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
66
<PackageTags>PowerShell;editor;development;language;debugging</PackageTags>
@@ -9,6 +9,5 @@
99
<RepositoryType>git</RepositoryType>
1010
<RepositoryUrl>https://github.com/PowerShell/PowerShellEditorServices</RepositoryUrl>
1111
<DebugType>portable</DebugType>
12-
<RuntimeFrameworkVersion>1.0.3</RuntimeFrameworkVersion>
1312
</PropertyGroup>
1413
</Project>

PowerShellEditorServices.build.ps1

+213-92
Large diffs are not rendered by default.

module/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.psm1

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
#
55

6-
if (!$PSVersionTable.PSEdition -or $PSVersionTable.PSEdition -eq "Desktop") {
7-
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.VSCode.dll"
8-
}
9-
else {
10-
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.VSCode.dll"
11-
}
6+
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Microsoft.PowerShell.EditorServices.VSCode.dll"
127

138
if ($psEditor -is [Microsoft.PowerShell.EditorServices.Extensions.EditorObject]) {
149
[Microsoft.PowerShell.EditorServices.VSCode.ComponentRegistration]::Register($psEditor.Components)

module/PowerShellEditorServices/PowerShellEditorServices.psm1

+13-8
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@
33
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
#
55

6-
if (!$PSVersionTable.PSEdition -or $PSVersionTable.PSEdition -eq "Desktop") {
7-
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.dll"
8-
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.Host.dll"
9-
}
10-
else {
11-
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.dll"
12-
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.Protocol.dll"
13-
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.Host.dll"
6+
# Need to load pipe handling shim assemblies in Windows PowerShell and PSCore 6.0 because they don't have WCP
7+
if ($PSEdition -eq 'Desktop') {
8+
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Desktop/System.IO.Pipes.AccessControl.dll"
9+
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Desktop/System.Security.AccessControl.dll"
10+
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Desktop/System.Security.Principal.Windows.dll"
11+
} elseif ($PSVersionTable.PSVersion -ge '6.0' -and $PSVersionTable.PSVersion -lt '6.1' -and $IsWindows) {
12+
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/6.0/System.IO.Pipes.AccessControl.dll"
13+
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/6.0/System.Security.AccessControl.dll"
14+
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/6.0/System.Security.Principal.Windows.dll"
1415
}
1516

17+
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Microsoft.PowerShell.EditorServices.dll"
18+
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Microsoft.PowerShell.EditorServices.Host.dll"
19+
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Microsoft.PowerShell.EditorServices.Protocol.dll"
20+
1621
function Start-EditorServicesHost {
1722
[CmdletBinding()]
1823
param(

scripts/travis.ps1

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
Get-Module PowerShellGet,PackageManagement | Remove-Module -Force -Verbose
2-
powershell -Command { Install-Module -Name PowershellGet -MinimumVersion 1.6 -Scope CurrentUser -force -confirm:$false -verbose }
3-
powershell -Command { Install-Module -Name PackageManagement -MinimumVersion 1.1.7.0 -Scope CurrentUser -Force -Confirm:$false -Verbose }
4-
Import-Module -Name PowerShellGet -MinimumVersion 1.6 -Force
5-
Import-Module -Name PackageManagement -MinimumVersion 1.1.7.0 -Force
6-
Install-PackageProvider -Name NuGet -Force | Out-Null
7-
Import-PackageProvider NuGet -Force | Out-Null
8-
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted | Out-Null
1+
$ErrorActionPreference = 'Stop'
92

103
# Install InvokeBuild
114
Install-Module InvokeBuild -MaximumVersion 5.1.0 -Scope CurrentUser -Force

src/PowerShellEditorServices.Host/EditorServicesHost.cs

+5-17
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ public EditorServicesHost(
125125
#endif
126126

127127
// Catch unhandled exceptions for logging purposes
128-
#if !CoreCLR
129128
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
130-
#endif
131129
}
132130

133131
#endregion
@@ -146,11 +144,8 @@ public void StartLogging(string logFilePath, LogLevel logLevel)
146144
.AddLogFile(logFilePath)
147145
.Build();
148146

149-
#if CoreCLR
150-
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(this.GetType().GetTypeInfo().Assembly.Location);
151-
#else
152-
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(this.GetType().Assembly.Location);
153-
#endif
147+
FileVersionInfo fileVersionInfo =
148+
FileVersionInfo.GetVersionInfo(this.GetType().GetTypeInfo().Assembly.Location);
154149

155150
string osVersion = RuntimeInformation.OSDescription;
156151

@@ -239,7 +234,7 @@ private async void OnLanguageServiceClientConnect(
239234
await this.editorSession.PowerShellContext.ImportCommandsModule(
240235
Path.Combine(
241236
Path.GetDirectoryName(this.GetType().GetTypeInfo().Assembly.Location),
242-
@"..\..\Commands"));
237+
@"..\Commands"));
243238

244239
this.languageServer.Start();
245240

@@ -454,19 +449,13 @@ private void ProtocolEndpoint_UnhandledException(object sender, Exception e)
454449
this.serverCompletedTask.SetException(e);
455450
}
456451

457-
#if !CoreCLR
458452
private void CurrentDomain_UnhandledException(
459453
object sender,
460454
UnhandledExceptionEventArgs e)
461455
{
462456
// Log the exception
463-
this.logger.Write(
464-
LogLevel.Error,
465-
string.Format(
466-
"FATAL UNHANDLED EXCEPTION:\r\n\r\n{0}",
467-
e.ExceptionObject.ToString()));
457+
this.logger.Write(LogLevel.Error, $"FATAL UNHANDLED EXCEPTION: {e.ExceptionObject}");
468458
}
469-
#endif
470459

471460
private IServerListener CreateServiceListener(MessageProtocolType protocol, EditorServiceTransportConfig config)
472461
{
@@ -504,7 +493,6 @@ private IServerListener CreateServiceListener(MessageProtocolType protocol, Edit
504493
/// <returns></returns>
505494
private string GetOSArchitecture()
506495
{
507-
#if !CoreCLR
508496
// If on win7 (version 6.1.x), avoid System.Runtime.InteropServices.RuntimeInformation
509497
if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version < new Version(6, 2))
510498
{
@@ -515,7 +503,7 @@ private string GetOSArchitecture()
515503

516504
return "X86";
517505
}
518-
#endif
506+
519507
return RuntimeInformation.OSArchitecture.ToString();
520508
}
521509

src/PowerShellEditorServices.Host/PowerShellEditorServices.Host.csproj

+7-18
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,19 @@
44
<PropertyGroup>
55
<AssemblyTitle>PowerShell Editor Services Host Process</AssemblyTitle>
66
<Description>Provides a process for hosting the PowerShell Editor Services library exposed by a JSON message protocol.</Description>
7-
<TargetFrameworks>netstandard1.6;net452</TargetFrameworks>
7+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
88
<AssemblyName>Microsoft.PowerShell.EditorServices.Host</AssemblyName>
99
</PropertyGroup>
1010

11+
<!--<PropertyGroup>
12+
<WarningsAsErrors>1591,1573,1572</WarningsAsErrors>
13+
<DocumentationFile>bin\$(TargetFramework)\$(Configuration)\Microsoft.PowerShell.EditorServices.xml</DocumentationFile>
14+
</PropertyGroup>-->
15+
1116
<ItemGroup>
1217
<ProjectReference Include="..\PowerShellEditorServices\PowerShellEditorServices.csproj" />
1318
<ProjectReference Include="..\PowerShellEditorServices.Protocol\PowerShellEditorServices.Protocol.csproj" />
19+
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0-preview-06" PrivateAssets="All"/>
1420
</ItemGroup>
1521

16-
<ItemGroup>
17-
<PackageReference Include="Newtonsoft.Json">
18-
<Version>10.0.3</Version>
19-
</PackageReference>
20-
<PackageReference Include="Microsoft.PowerShell.SDK">
21-
<Version>6.0.0-alpha13</Version>
22-
</PackageReference>
23-
</ItemGroup>
24-
25-
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">
26-
<DefineConstants>$(DefineConstants);CoreCLR</DefineConstants>
27-
</PropertyGroup>
28-
29-
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
30-
<Reference Include="System" />
31-
<Reference Include="Microsoft.CSharp" />
32-
</ItemGroup>
3322
</Project>

src/PowerShellEditorServices.Protocol/MessageProtocol/Channel/NamedPipeClientChannel.cs

-17
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,7 @@ public static async Task<NamedPipeClientChannel> Connect(
6969
PipeDirection.InOut,
7070
PipeOptions.Asynchronous);
7171

72-
#if CoreCLR
7372
await pipeClient.ConnectAsync();
74-
#else
75-
while (!pipeClient.IsConnected)
76-
{
77-
try
78-
{
79-
// Wait for 500 milliseconds so that we don't tie up the thread
80-
pipeClient.Connect(500);
81-
}
82-
catch (TimeoutException)
83-
{
84-
// Connect timed out, wait and try again
85-
await Task.Delay(1000);
86-
continue;
87-
}
88-
}
89-
#endif
9073
var clientChannel = new NamedPipeClientChannel(pipeClient, logger);
9174
clientChannel.Start(messageProtocolType);
9275

src/PowerShellEditorServices.Protocol/MessageProtocol/Channel/StdioServerChannel.cs

+9-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ public StdioServerChannel(ILogger logger)
2727

2828
protected override void Initialize(IMessageSerializer messageSerializer)
2929
{
30-
#if !CoreCLR
31-
// Ensure that the console is using UTF-8 encoding
32-
System.Console.InputEncoding = Encoding.UTF8;
33-
System.Console.OutputEncoding = Encoding.UTF8;
34-
#endif
30+
if (System.Console.InputEncoding != Encoding.UTF8)
31+
{
32+
System.Console.InputEncoding = Encoding.UTF8;
33+
}
34+
35+
if (System.Console.OutputEncoding != Encoding.UTF8)
36+
{
37+
System.Console.OutputEncoding = Encoding.UTF8;
38+
}
3539

3640
// Open the standard input/output streams
3741
this.inputStream = System.Console.OpenStandardInput();

src/PowerShellEditorServices.Protocol/PowerShellEditorServices.Protocol.csproj

+8-14
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,19 @@
33
<PropertyGroup>
44
<AssemblyTitle>PowerShell Editor Services Host Protocol Library</AssemblyTitle>
55
<Description>Provides message types and client/server APIs for the PowerShell Editor Services JSON protocol.</Description>
6-
<TargetFrameworks>netstandard1.6;net452;</TargetFrameworks>
6+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
77
<AssemblyName>Microsoft.PowerShell.EditorServices.Protocol</AssemblyName>
88
</PropertyGroup>
9+
<!--<PropertyGroup>
10+
<WarningsAsErrors>1591,1573,1572</WarningsAsErrors>
11+
<DocumentationFile>bin\$(TargetFramework)\$(Configuration)\Microsoft.PowerShell.EditorServices.xml</DocumentationFile>
12+
</PropertyGroup>-->
913
<ItemGroup>
1014
<ProjectReference Include="..\PowerShellEditorServices\PowerShellEditorServices.csproj" />
1115
</ItemGroup>
1216
<ItemGroup>
13-
<PackageReference Include="Newtonsoft.Json" Version="10.0.3">
14-
</PackageReference>
15-
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.0.0-alpha13">
16-
</PackageReference>
17-
<PackageReference Include="System.IO.Pipes.AccessControl" Version="4.5.1" Condition=" '$(TargetFramework)' == 'netstandard1.6' " />
18-
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
19-
</ItemGroup>
20-
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">
21-
<DefineConstants>$(DefineConstants);CoreCLR</DefineConstants>
22-
</PropertyGroup>
23-
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
24-
<Reference Include="System" />
25-
<Reference Include="Microsoft.CSharp" />
17+
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
18+
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0-preview-06" PrivateAssets="All" />
19+
<PackageReference Include="System.IO.Pipes.AccessControl" Version="4.5.1" />
2620
</ItemGroup>
2721
</Project>

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

-5
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,7 @@ protected async Task HandleLaunchRequest(
290290
// pick some reasonable default.
291291
if (string.IsNullOrEmpty(workingDir) && launchParams.CreateTemporaryIntegratedConsole)
292292
{
293-
#if CoreCLR
294-
//TODO: RKH 2018-06-26 .NET standard 2.0 has added Environment.CurrentDirectory - let's use it.
295-
workingDir = AppContext.BaseDirectory;
296-
#else
297293
workingDir = Environment.CurrentDirectory;
298-
#endif
299294
}
300295

301296
// At this point, we will either have a working dir that should be set to cwd in

src/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.csproj

+2-10
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
<PropertyGroup>
55
<AssemblyTitle>PowerShell Editor Services, Visual Studio Code Extensions</AssemblyTitle>
66
<Description>Provides added functionality to PowerShell Editor Services for the Visual Studio Code editor.</Description>
7-
<TargetFrameworks>netstandard1.6;net452</TargetFrameworks>
7+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
88
<AssemblyName>Microsoft.PowerShell.EditorServices.VSCode</AssemblyName>
99
</PropertyGroup>
1010

1111
<!-- Fail the release build if there are missing public API documentation comments -->
12-
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
12+
<PropertyGroup>
1313
<WarningsAsErrors>1591,1573,1572</WarningsAsErrors>
1414
<DocumentationFile>bin\$(TargetFramework)\$(Configuration)\Microsoft.PowerShell.EditorServices.VSCode.xml</DocumentationFile>
1515
</PropertyGroup>
@@ -20,12 +20,4 @@
2020
<ProjectReference Include="..\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj" />
2121
</ItemGroup>
2222

23-
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">
24-
<DefineConstants>$(DefineConstants);CoreCLR</DefineConstants>
25-
</PropertyGroup>
26-
27-
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
28-
<Reference Include="System" />
29-
<Reference Include="Microsoft.CSharp" />
30-
</ItemGroup>
3123
</Project>

src/PowerShellEditorServices/Analysis/AnalysisService.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,12 @@ private static RunspacePool CreatePssaRunspacePool(out PSModuleInfo pssaModuleIn
611611
}
612612

613613
// Create a base session state with PSScriptAnalyzer loaded
614-
InitialSessionState sessionState = InitialSessionState.CreateDefault2();
614+
InitialSessionState sessionState;
615+
if (Environment.GetEnvironmentVariable("PSES_TEST_USE_CREATE_DEFAULT") == "1") {
616+
sessionState = InitialSessionState.CreateDefault();
617+
} else {
618+
sessionState = InitialSessionState.CreateDefault2();
619+
}
615620
sessionState.ImportPSModule(new [] { pssaModuleInfo.ModuleBase });
616621

617622
// RunspacePool takes care of queuing commands for us so we do not

src/PowerShellEditorServices/Console/ConsoleProxy.cs

-5
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,13 @@ internal static class ConsoleProxy
2020

2121
static ConsoleProxy()
2222
{
23-
// Maybe we should just include the RuntimeInformation package for FullCLR?
24-
#if CoreCLR
2523
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
2624
{
2725
s_consoleProxy = new WindowsConsoleOperations();
2826
return;
2927
}
3028

3129
s_consoleProxy = new UnixConsoleOperations();
32-
#else
33-
s_consoleProxy = new WindowsConsoleOperations();
34-
#endif
3530
}
3631

3732
public static Task<ConsoleKeyInfo> ReadKeyAsync(CancellationToken cancellationToken) =>

src/PowerShellEditorServices/Language/CompletionResults.cs

-2
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,8 @@ private static CompletionType ConvertCompletionResultType(
305305
case CompletionResultType.Type:
306306
return CompletionType.Type;
307307

308-
#if !PowerShellv3
309308
case CompletionResultType.Keyword:
310309
return CompletionType.Keyword;
311-
#endif
312310

313311
case CompletionResultType.ProviderContainer:
314312
return CompletionType.Folder;

src/PowerShellEditorServices/Language/FindSymbolsVisitor2.cs

-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
namespace Microsoft.PowerShell.EditorServices
1010
{
11-
#if PowerShellv5
12-
1311
// TODO: Restore this when we figure out how to support multiple
1412
// PS versions in the new PSES-as-a-module world (issue #276)
1513

@@ -78,6 +76,5 @@ namespace Microsoft.PowerShell.EditorServices
7876
// return AstVisitAction.Continue;
7977
// }
8078
//}
81-
#endif
8279
}
8380

0 commit comments

Comments
 (0)