Skip to content

Commit 67af232

Browse files
authored
Migrate to netstandard2.0 and PSStandard (#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 0a29e44 commit 67af232

File tree

74 files changed

+776
-1020
lines changed

Some content is hidden

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

74 files changed

+776
-1020
lines changed

.travis.yml

+8-7
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
@@ -26,4 +27,4 @@ install:
2627

2728
script:
2829
- ulimit -n 4096
29-
- powershell -File scripts/travis.ps1
30+
- pwsh -File scripts/travis.ps1

PowerShellEditorServices.Common.props

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<VersionPrefix>1.8.2</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

+214-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/download.sh

+1-151
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,3 @@
11
#!/usr/bin/env bash
22

3-
# Let's quit on interrupt of subcommands
4-
trap '
5-
trap - INT # restore default INT handler
6-
echo "Interrupted"
7-
kill -s INT "$$"
8-
' INT
9-
10-
get_url() {
11-
fork=$2
12-
release=v6.0.0-beta.1
13-
echo "https://github.com/$fork/PowerShell/releases/download/$release/$1"
14-
}
15-
16-
fork="PowerShell"
17-
# Get OS specific asset ID and package name
18-
case "$OSTYPE" in
19-
linux*)
20-
source /etc/os-release
21-
# Install curl and wget to download package
22-
case "$ID" in
23-
centos*)
24-
if ! hash curl 2>/dev/null; then
25-
echo "curl not found, installing..."
26-
sudo yum install -y curl
27-
fi
28-
29-
package=powershell-6.0.0_beta.1-1.el7.centos.x86_64.rpm
30-
;;
31-
ubuntu)
32-
if ! hash curl 2>/dev/null; then
33-
echo "curl not found, installing..."
34-
sudo apt-get install -y curl
35-
fi
36-
37-
case "$VERSION_ID" in
38-
14.04)
39-
package=powershell_6.0.0-beta.1-1ubuntu1.14.04.1_amd64.deb
40-
;;
41-
16.04)
42-
package=powershell_6.0.0-beta.1-1ubuntu1.16.04.1_amd64.deb
43-
;;
44-
*)
45-
echo "Ubuntu $VERSION_ID is not supported!" >&2
46-
exit 2
47-
esac
48-
;;
49-
opensuse)
50-
if ! hash curl 2>/dev/null; then
51-
echo "curl not found, installing..."
52-
sudo zypper install -y curl
53-
fi
54-
55-
56-
case "$VERSION_ID" in
57-
42.1)
58-
# TODO during next release remove fork and fix package name
59-
fork=TravisEz13
60-
package=powershell-6.0.0_beta.1-1.suse.42.1.x86_64.rpm
61-
;;
62-
*)
63-
echo "OpenSUSE $VERSION_ID is not supported!" >&2
64-
exit 2
65-
esac
66-
;;
67-
*)
68-
echo "$NAME is not supported!" >&2
69-
exit 2
70-
esac
71-
;;
72-
darwin*)
73-
# We don't check for curl as macOS should have a system version
74-
package=powershell-6.0.0-beta.1-osx.10.12-x64.pkg
75-
;;
76-
*)
77-
echo "$OSTYPE is not supported!" >&2
78-
exit 2
79-
;;
80-
esac
81-
82-
curl -L -o "$package" $(get_url "$package" "$fork")
83-
84-
if [[ ! -r "$package" ]]; then
85-
echo "ERROR: $package failed to download! Aborting..." >&2
86-
exit 1
87-
fi
88-
89-
# Installs PowerShell package
90-
case "$OSTYPE" in
91-
linux*)
92-
source /etc/os-release
93-
# Install dependencies
94-
echo "Installing PowerShell with sudo..."
95-
case "$ID" in
96-
centos)
97-
# yum automatically resolves dependencies for local packages
98-
sudo yum install "./$package"
99-
;;
100-
ubuntu)
101-
# dpkg does not automatically resolve dependencies, but spouts ugly errors
102-
sudo dpkg -i "./$package" &> /dev/null
103-
# Resolve dependencies
104-
sudo apt-get install -f
105-
;;
106-
opensuse)
107-
# Install the Microsoft public key so that zypper trusts the package
108-
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
109-
# zypper automatically resolves dependencies for local packages
110-
sudo zypper --non-interactive install "./$package" &> /dev/null
111-
;;
112-
*)
113-
esac
114-
;;
115-
darwin*)
116-
patched=0
117-
if hash brew 2>/dev/null; then
118-
brew update
119-
if [[ ! -d $(brew --prefix openssl) ]]; then
120-
echo "Installing OpenSSL with brew..."
121-
if ! brew install openssl; then
122-
echo "ERROR: OpenSSL failed to install! Crypto functions will not work..." >&2
123-
# Don't abort because it is not fatal
124-
elif ! brew install curl --with-openssl; then
125-
echo "ERROR: curl failed to build against OpenSSL; SSL functions will not work..." >&2
126-
# Still not fatal
127-
else
128-
# OpenSSL installation succeeded; reme mber to patch System.Net.Http after PowerShell installation
129-
patched=1
130-
fi
131-
fi
132-
133-
else
134-
echo "ERROR: brew not found! OpenSSL may not be available..." >&2
135-
# Don't abort because it is not fatal
136-
fi
137-
138-
echo "Installing $package with sudo ..."
139-
sudo installer -pkg "./$package" -target /
140-
if [[ $patched -eq 1 ]]; then
141-
echo "Patching System.Net.Http for libcurl and OpenSSL..."
142-
find /usr/local/microsoft/powershell -name System.Net.Http.Native.dylib | xargs sudo install_name_tool -change /usr/lib/libcurl.4.dylib /usr/local/opt/curl/lib/libcurl.4.dylib
143-
fi
144-
;;
145-
esac
146-
147-
powershell -noprofile -c '"Congratulations! PowerShell is installed at $PSHOME"'
148-
success=$?
149-
150-
if [[ "$success" != 0 ]]; then
151-
echo "ERROR: PowerShell failed to install!" >&2
152-
exit "$success"
153-
fi
3+
bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh)

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

+6-26
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Management.Automation.Runspaces;
2020
using System.Reflection;
2121
using System.Threading.Tasks;
22+
using System.Runtime.InteropServices;
2223

2324
namespace Microsoft.PowerShell.EditorServices.Host
2425
{
@@ -118,9 +119,7 @@ public EditorServicesHost(
118119
#endif
119120

120121
// Catch unhandled exceptions for logging purposes
121-
#if !CoreCLR
122122
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
123-
#endif
124123
}
125124

126125
#endregion
@@ -139,21 +138,12 @@ public void StartLogging(string logFilePath, LogLevel logLevel)
139138
.AddLogFile(logFilePath)
140139
.Build();
141140

142-
#if CoreCLR
143141
FileVersionInfo fileVersionInfo =
144142
FileVersionInfo.GetVersionInfo(this.GetType().GetTypeInfo().Assembly.Location);
145143

146-
// TODO #278: Need the correct dependency package for this to work correctly
147-
//string osVersionString = RuntimeInformation.OSDescription;
148-
//string processArchitecture = RuntimeInformation.ProcessArchitecture == Architecture.X64 ? "64-bit" : "32-bit";
149-
//string osArchitecture = RuntimeInformation.OSArchitecture == Architecture.X64 ? "64-bit" : "32-bit";
150-
#else
151-
FileVersionInfo fileVersionInfo =
152-
FileVersionInfo.GetVersionInfo(this.GetType().Assembly.Location);
153-
string osVersionString = Environment.OSVersion.VersionString;
154-
string processArchitecture = Environment.Is64BitProcess ? "64-bit" : "32-bit";
155-
string osArchitecture = Environment.Is64BitOperatingSystem ? "64-bit" : "32-bit";
156-
#endif
144+
string osVersionString = RuntimeInformation.OSDescription;
145+
string processArchitecture = RuntimeInformation.ProcessArchitecture == Architecture.X64 ? "64-bit" : "32-bit";
146+
string osArchitecture = RuntimeInformation.OSArchitecture == Architecture.X64 ? "64-bit" : "32-bit";
157147

158148
string newLine = Environment.NewLine;
159149

@@ -165,14 +155,10 @@ public void StartLogging(string logFilePath, LogLevel logLevel)
165155
$" Name: {this.hostDetails.Name}" + newLine +
166156
$" ProfileId: {this.hostDetails.ProfileId}" + newLine +
167157
$" Version: {this.hostDetails.Version}" + newLine +
168-
#if !CoreCLR
169158
$" Arch: {processArchitecture}" + newLine + newLine +
170159
" Operating system details:" + newLine + newLine +
171160
$" Version: {osVersionString}" + newLine +
172161
$" Arch: {osArchitecture}"));
173-
#else
174-
""));
175-
#endif
176162
}
177163

178164
/// <summary>
@@ -231,7 +217,7 @@ private async void OnLanguageServiceClientConnect(
231217
await this.editorSession.PowerShellContext.ImportCommandsModule(
232218
Path.Combine(
233219
Path.GetDirectoryName(this.GetType().GetTypeInfo().Assembly.Location),
234-
@"..\..\Commands"));
220+
@"..\Commands"));
235221

236222
this.languageServer.Start();
237223

@@ -441,19 +427,13 @@ private void ProtocolEndpoint_UnhandledException(object sender, Exception e)
441427
this.serverCompletedTask.SetException(e);
442428
}
443429

444-
#if !CoreCLR
445430
private void CurrentDomain_UnhandledException(
446431
object sender,
447432
UnhandledExceptionEventArgs e)
448433
{
449434
// Log the exception
450-
this.logger.Write(
451-
LogLevel.Error,
452-
string.Format(
453-
"FATAL UNHANDLED EXCEPTION:\r\n\r\n{0}",
454-
e.ExceptionObject.ToString()));
435+
this.logger.Write(LogLevel.Error, $"FATAL UNHANDLED EXCEPTION: {e.ExceptionObject}");
455436
}
456-
#endif
457437
private IServerListener CreateServiceListener(MessageProtocolType protocol, EditorServiceTransportConfig config)
458438
{
459439
switch (config.TransportType)

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;net451</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)' == 'net451' ">
30-
<Reference Include="System" />
31-
<Reference Include="Microsoft.CSharp" />
32-
</ItemGroup>
3322
</Project>

0 commit comments

Comments
 (0)