Skip to content

Commit 49604e8

Browse files
authored
Update PSReadLine build to target netstandard2.0 (#4584)
By retargeting PSReadLine to `netstandard2.0`, we can simplify the build a lot and produce the same assembly no matter building on Windows or non-Windows. - Update PSReadLine build to target `netstandard2.0`, including the CI and release pipeline YAML files. - Update the test to target `net472` and `net6.0`, so that we can run tests with both .NET Framework and .NET - Rename `Microsoft.PowerShell.PSReadLine2.dll` to `Microsoft.PowerShell.PSReadLine.dll` - Update and clean up the `README.md` with the up-to-date information
1 parent a272810 commit 49604e8

File tree

12 files changed

+115
-228
lines changed

12 files changed

+115
-228
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,7 @@ Additional references:
6565

6666
### Bootstrap, Build and Test
6767

68-
To build `PSReadLine` on Windows, Linux, or macOS,
69-
you must have the following installed:
70-
71-
* .NET Core SDK 2.1.802 or [a newer version](https://www.microsoft.com/net/download)
72-
* The PowerShell modules `InvokeBuild` and `platyPS`
73-
74-
The build script `build.ps1` can be used to bootstrap, build and test the project.
75-
76-
* Bootstrap: `./build.ps1 -Bootstrap`
77-
* Build:
78-
* Targeting .NET 4.6.2 (Windows only): `./build.ps1 -Configuration Debug -Framework net462`
79-
* Targeting .NET Core: `./build.ps1 -Configuration Debug -Framework net6.0`
80-
* Test:
81-
* Targeting .NET 4.6.2 (Windows only): `./build.ps1 -Test -Configuration Debug -Framework net462`
82-
* Targeting .NET Core: `./build.ps1 -Test -Configuration Debug -Framework net6.0`
83-
84-
After build, the produced artifacts can be found at `<your-local-repo-root>/bin/Debug`.
68+
See the [Building](../README.md#building) section in README for details.
8569

8670
### Submitting Pull Request
8771

.pipelines/PSReadLine-Official.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ extends:
114114
- pwsh: |
115115
Write-Host "PS Version: $($($PSVersionTable.PSVersion))"
116116
Set-Location -Path '$(repoRoot)'
117-
.\build.ps1 -Configuration Release -Framework net462
117+
.\build.ps1 -Configuration Release
118118
displayName: Build
119119
env:
120120
# Set ob_restore_phase to run this step before '🔒 Setup Signing' step.
@@ -166,7 +166,7 @@ extends:
166166
TargetFolder: $(ob_outputDirectory)
167167

168168
- pwsh: |
169-
$versionInfo = Get-Item "$(signSrcPath)\Microsoft.PowerShell.PSReadLine2.dll" | ForEach-Object VersionInfo
169+
$versionInfo = Get-Item "$(signSrcPath)\Microsoft.PowerShell.PSReadLine.dll" | ForEach-Object VersionInfo
170170
$moduleVersion = $versionInfo.ProductVersion.Split('+')[0]
171171
$vstsCommandString = "vso[task.setvariable variable=ob_sdl_sbom_packageversion]${moduleVersion}"
172172

MockPSConsole/MockPSConsole.csproj

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@
44
<OutputType>Exe</OutputType>
55
<RootNamespace>MockPSConsole</RootNamespace>
66
<AssemblyName>MockPSConsole</AssemblyName>
7-
<TargetFrameworks>net462;net6.0</TargetFrameworks>
7+
<TargetFrameworks>net472;net6.0</TargetFrameworks>
88
<FileAlignment>512</FileAlignment>
99
<ApplicationManifest>Program.manifest</ApplicationManifest>
1010
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
1111
</PropertyGroup>
1212

13-
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
14-
<PackageReference Include="System.Xml.XDocument" version="4.3.0" />
15-
<PackageReference Include="System.Data.DataSetExtensions" version="4.5.0" />
16-
<PackageReference Include="Microsoft.CSharp" version="4.7.0" />
13+
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
1714
<PackageReference Include="PowerShellStandard.Library" version="5.1.0" />
1815
</ItemGroup>
1916

2017
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
21-
<PackageReference Include="Microsoft.PowerShell.SDK" version="7.2.23" />
18+
<PackageReference Include="Microsoft.PowerShell.SDK" version="7.2.24" />
2219
</ItemGroup>
2320

2421
<ItemGroup>

PSReadLine.build.ps1

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ param(
1919
[ValidateSet("Debug", "Release")]
2020
[string]$Configuration = (property Configuration Release),
2121

22-
[ValidateSet("net462", "net6.0")]
23-
[string]$Framework,
22+
[ValidateSet("net472", "net6.0")]
23+
[string]$TestFramework,
2424

2525
[switch]$CheckHelpContent
2626
)
@@ -30,71 +30,58 @@ Import-Module "$PSScriptRoot/tools/helper.psm1"
3030
# Final bits to release go here
3131
$targetDir = "bin/$Configuration/PSReadLine"
3232

33-
if (-not $Framework)
34-
{
35-
$Framework = if ($PSVersionTable.PSEdition -eq "Core") { "net6.0" } else { "net462" }
33+
if (-not $TestFramework) {
34+
$TestFramework = $IsWindows ? "net472" : "net6.0"
3635
}
3736

38-
Write-Verbose "Building for '$Framework'" -Verbose
39-
4037
function ConvertTo-CRLF([string] $text) {
4138
$text.Replace("`r`n","`n").Replace("`n","`r`n")
4239
}
4340

4441
$polyFillerParams = @{
4542
Inputs = { Get-ChildItem Polyfill/*.cs, Polyfill/Polyfill.csproj }
46-
Outputs = "Polyfill/bin/$Configuration/$Framework/Microsoft.PowerShell.PSReadLine.Polyfiller.dll"
43+
Outputs = "Polyfill/bin/$Configuration/netstandard2.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll"
4744
}
4845

4946
$binaryModuleParams = @{
5047
Inputs = { Get-ChildItem PSReadLine/*.cs, PSReadLine/PSReadLine.csproj, PSReadLine/PSReadLineResources.resx, Polyfill/*.cs, Polyfill/Polyfill.csproj }
51-
Outputs = "PSReadLine/bin/$Configuration/$Framework/Microsoft.PowerShell.PSReadLine2.dll"
48+
Outputs = "PSReadLine/bin/$Configuration/netstandard2.0/Microsoft.PowerShell.PSReadLine.dll"
5249
}
5350

5451
$xUnitTestParams = @{
5552
Inputs = { Get-ChildItem test/*.cs, test/*.json, test/PSReadLine.Tests.csproj }
56-
Outputs = "test/bin/$Configuration/$Framework/PSReadLine.Tests.dll"
57-
}
58-
59-
$mockPSConsoleParams = @{
60-
Inputs = { Get-ChildItem MockPSConsole/*.cs, MockPSConsole/Program.manifest, MockPSConsole/MockPSConsole.csproj }
61-
Outputs = "MockPSConsole/bin/$Configuration/$Framework/MockPSConsole.dll"
53+
Outputs = "test/bin/$Configuration/$TestFramework/PSReadLine.Tests.dll"
6254
}
6355

6456
<#
6557
Synopsis: Build the Polyfiller assembly
6658
#>
67-
task BuildPolyfiller @polyFillerParams -If ($Framework -eq "net462") {
68-
## Build both "net462" and "net6.0"
69-
exec { dotnet publish -f "net462" -c $Configuration Polyfill }
70-
exec { dotnet publish -f "net6.0" -c $Configuration Polyfill }
59+
task BuildPolyfiller @polyFillerParams {
60+
exec { dotnet publish -c $Configuration -f 'netstandard2.0' Polyfill }
61+
exec { dotnet publish -c $Configuration -f 'net6.0' Polyfill }
7162
}
7263

7364
<#
7465
Synopsis: Build main binary module
7566
#>
7667
task BuildMainModule @binaryModuleParams {
77-
exec { dotnet publish -f $Framework -c $Configuration PSReadLine }
68+
exec { dotnet publish -c $Configuration PSReadLine\PSReadLine.csproj }
7869
}
7970

8071
<#
8172
Synopsis: Build xUnit tests
8273
#>
8374
task BuildXUnitTests @xUnitTestParams {
84-
exec { dotnet publish -f $Framework -c $Configuration test }
85-
}
86-
87-
<#
88-
Synopsis: Build the mock powershell console.
89-
#>
90-
task BuildMockPSConsole @mockPSConsoleParams {
91-
exec { dotnet publish -f $Framework -c $Configuration MockPSConsole }
75+
exec { dotnet publish -f $TestFramework -c $Configuration test }
9276
}
9377

9478
<#
9579
Synopsis: Run the unit tests
9680
#>
97-
task RunTests BuildMainModule, BuildXUnitTests, { Start-TestRun -Configuration $Configuration -Framework $Framework }
81+
task RunTests BuildMainModule, BuildXUnitTests, {
82+
Write-Verbose "Run tests targeting '$TestFramework' ..."
83+
Start-TestRun -Configuration $Configuration -Framework $TestFramework
84+
}
9885

9986
<#
10087
Synopsis: Check if the help content is in sync.
@@ -128,35 +115,27 @@ task LayoutModule BuildPolyfiller, BuildMainModule, {
128115
Set-Content -Path (Join-Path $targetDir (Split-Path $file -Leaf)) -Value (ConvertTo-CRLF $content) -Force
129116
}
130117

131-
if ($Framework -eq "net462") {
132-
if (-not (Test-Path "$targetDir/net462")) {
133-
New-Item "$targetDir/net462" -ItemType Directory -Force > $null
134-
}
135-
if (-not (Test-Path "$targetDir/net6plus")) {
136-
New-Item "$targetDir/net6plus" -ItemType Directory -Force > $null
137-
}
138-
139-
Copy-Item "Polyfill/bin/$Configuration/net462/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" "$targetDir/net462" -Force
140-
Copy-Item "Polyfill/bin/$Configuration/net6.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" "$targetDir/net6plus" -Force
118+
if (-not (Test-Path "$targetDir/netstd")) {
119+
New-Item "$targetDir/netstd" -ItemType Directory -Force > $null
120+
}
121+
if (-not (Test-Path "$targetDir/net6plus")) {
122+
New-Item "$targetDir/net6plus" -ItemType Directory -Force > $null
141123
}
142124

143-
$binPath = "PSReadLine/bin/$Configuration/$Framework/publish"
144-
Copy-Item $binPath/Microsoft.PowerShell.PSReadLine2.dll $targetDir
125+
Copy-Item "Polyfill/bin/$Configuration/netstandard2.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" "$targetDir/netstd" -Force
126+
Copy-Item "Polyfill/bin/$Configuration/net6.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" "$targetDir/net6plus" -Force
127+
128+
$binPath = "PSReadLine/bin/$Configuration/netstandard2.0/publish"
129+
Copy-Item $binPath/Microsoft.PowerShell.PSReadLine.dll $targetDir
145130
Copy-Item $binPath/Microsoft.PowerShell.Pager.dll $targetDir
146131

147132
if ($Configuration -eq 'Debug') {
148133
Copy-Item $binPath/*.pdb $targetDir
149134
}
150135

151-
if (Test-Path $binPath/System.Runtime.InteropServices.RuntimeInformation.dll) {
152-
Copy-Item $binPath/System.Runtime.InteropServices.RuntimeInformation.dll $targetDir
153-
} else {
154-
Write-Warning "Build using $Framework is not sufficient to be downlevel compatible"
155-
}
156-
157136
# Copy module manifest, but fix the version to match what we've specified in the binary module.
158137
$moduleManifestContent = ConvertTo-CRLF (Get-Content -Path 'PSReadLine/PSReadLine.psd1' -Raw)
159-
$versionInfo = (Get-ChildItem -Path $targetDir/Microsoft.PowerShell.PSReadLine2.dll).VersionInfo
138+
$versionInfo = (Get-ChildItem -Path $targetDir/Microsoft.PowerShell.PSReadLine.dll).VersionInfo
160139
$version = $versionInfo.FileVersion
161140
$semVer = $versionInfo.ProductVersion
162141

PSReadLine/OnImportAndRemove.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
2828
}
2929

3030
string root = Path.GetDirectoryName(typeof(OnModuleImportAndRemove).Assembly.Location);
31-
string subd = (Environment.Version.Major >= 6) ? "net6plus" : "net462";
31+
string subd = (Environment.Version.Major >= 6) ? "net6plus" : "netstd";
3232
string path = Path.Combine(root, subd, "Microsoft.PowerShell.PSReadLine.Polyfiller.dll");
3333

3434
return Assembly.LoadFrom(path);

PSReadLine/PSReadLine.csproj

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,23 @@
33
<PropertyGroup>
44
<OutputType>Library</OutputType>
55
<RootNamespace>Microsoft.PowerShell.PSReadLine</RootNamespace>
6-
<AssemblyName>Microsoft.PowerShell.PSReadLine2</AssemblyName>
6+
<AssemblyName>Microsoft.PowerShell.PSReadLine</AssemblyName>
77
<NoWarn>$(NoWarn);CA1416</NoWarn>
88
<AssemblyVersion>2.4.0.0</AssemblyVersion>
99
<FileVersion>2.4.0</FileVersion>
1010
<InformationalVersion>2.4.0-beta0</InformationalVersion>
1111
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
12-
<TargetFrameworks>net462;net6.0</TargetFrameworks>
12+
<TargetFramework>netstandard2.0</TargetFramework>
1313
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
14+
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
1415
<LangVersion>9.0</LangVersion>
1516
</PropertyGroup>
1617

17-
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
18+
<ItemGroup>
1819
<PackageReference Include="PowerShellStandard.Library" version="5.1.0" />
1920
<PackageReference Include="Microsoft.CSharp" version="4.7.0" />
20-
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" />
21-
<ProjectReference Include="..\Polyfill\Polyfill.csproj" />
22-
</ItemGroup>
23-
24-
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
25-
<PackageReference Include="System.Management.Automation" Version="7.2.23" />
26-
</ItemGroup>
27-
28-
<ItemGroup>
2921
<PackageReference Include="Microsoft.PowerShell.Pager" version="1.0.0" />
22+
<ProjectReference Include="..\Polyfill\Polyfill.csproj" />
3023
</ItemGroup>
3124

3225
<ItemGroup>

PSReadLine/PSReadLine.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
RootModule = 'PSReadLine.psm1'
3-
NestedModules = @("Microsoft.PowerShell.PSReadLine2.dll")
3+
NestedModules = @("Microsoft.PowerShell.PSReadLine.dll")
44
ModuleVersion = '2.4.0'
55
GUID = '5714753b-2afd-4492-a5fd-01d9e2cff8b5'
66
Author = 'Microsoft Corporation'

Polyfill/Polyfill.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
<PropertyGroup>
44
<AssemblyName>Microsoft.PowerShell.PSReadLine.Polyfiller</AssemblyName>
55
<AssemblyVersion>1.0.0.0</AssemblyVersion>
6-
<TargetFrameworks>net462;net6.0</TargetFrameworks>
6+
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
77
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
88
</PropertyGroup>
99

10-
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
10+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
1111
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" />
1212
</ItemGroup>
1313

1414
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
15-
<PackageReference Include="System.Management.Automation" Version="7.2.23" />
15+
<PackageReference Include="System.Management.Automation" Version="7.2.24" />
1616
</ItemGroup>
1717

18-
<PropertyGroup Condition="'$(TargetFramework)' == 'net462'">
18+
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
1919
<DefineConstants>$(DefineConstants);LEGACY</DefineConstants>
2020
</PropertyGroup>
2121

0 commit comments

Comments
 (0)