Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"-NoProfile",
"-NoExit",
"-Command",
"Import-Module '${workspaceFolder}/PSReadLine/bin/Debug/netstandard2.0/PSReadLine.psd1'"
"Import-Module '${workspaceFolder}/PSReadLine/bin/Debug/net8.0/PSReadLine.psd1'"
],
"console": "integratedTerminal",
"justMyCode": false,
Expand Down
10 changes: 3 additions & 7 deletions MockPSConsole/MockPSConsole.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
<OutputType>Exe</OutputType>
<RootNamespace>MockPSConsole</RootNamespace>
<AssemblyName>MockPSConsole</AssemblyName>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<FileAlignment>512</FileAlignment>
<ApplicationManifest>Program.manifest</ApplicationManifest>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
<PackageReference Include="PowerShellStandard.Library" version="5.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.PowerShell.SDK" version="7.2.24" />
<ItemGroup>
<PackageReference Include="Microsoft.PowerShell.SDK" version="7.4.13" />
</ItemGroup>

<ItemGroup>
Expand Down
57 changes: 19 additions & 38 deletions PSReadLine.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,37 @@ param(
[ValidateSet("Debug", "Release")]
[string]$Configuration = (property Configuration Release),

[ValidateSet("net472", "net6.0")]
[string]$TestFramework,

[switch]$CheckHelpContent
)

Import-Module "$PSScriptRoot/tools/helper.psm1"

# Final bits to release go here
$targetDir = "bin/$Configuration/PSReadLine"
# Dynamically read target framework from project file
$csprojPath = "$PSScriptRoot/PSReadLine/PSReadLine.csproj"
[xml]$csproj = Get-Content $csprojPath
$targetFramework = $csproj.Project.PropertyGroup.TargetFramework | Where-Object { $_ } | Select-Object -First 1

if (-not $TestFramework) {
$TestFramework = $IsWindows ? "net472" : "net6.0"
if (-not $targetFramework) {
throw "Could not determine TargetFramework from $csprojPath"
}

Write-Verbose "Target framework: $targetFramework"

# Final bits to release go here
$targetDir = "bin/$Configuration/PSReadLine"

function ConvertTo-CRLF([string] $text) {
$text.Replace("`r`n","`n").Replace("`n","`r`n")
}

$polyFillerParams = @{
Inputs = { Get-ChildItem Polyfill/*.cs, Polyfill/Polyfill.csproj }
Outputs = "Polyfill/bin/$Configuration/netstandard2.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll"
}

$binaryModuleParams = @{
Inputs = { Get-ChildItem PSReadLine/*.cs, PSReadLine/PSReadLine.csproj, PSReadLine/PSReadLineResources.resx, Polyfill/*.cs, Polyfill/Polyfill.csproj }
Outputs = "PSReadLine/bin/$Configuration/netstandard2.0/Microsoft.PowerShell.PSReadLine.dll"
Inputs = { Get-ChildItem PSReadLine/*.cs, PSReadLine/PSReadLine.csproj, PSReadLine/PSReadLineResources.resx }
Outputs = "PSReadLine/bin/$Configuration/$targetFramework/Microsoft.PowerShell.PSReadLine.dll"
}

$xUnitTestParams = @{
Inputs = { Get-ChildItem test/*.cs, test/*.json, test/PSReadLine.Tests.csproj }
Outputs = "test/bin/$Configuration/$TestFramework/PSReadLine.Tests.dll"
}

<#
Synopsis: Build the Polyfiller assembly
#>
task BuildPolyfiller @polyFillerParams {
exec { dotnet publish -c $Configuration -f 'netstandard2.0' Polyfill }
exec { dotnet publish -c $Configuration -f 'net6.0' Polyfill }
Outputs = "test/bin/$Configuration/$targetFramework/PSReadLine.Tests.dll"
}

<#
Expand All @@ -72,15 +63,15 @@ task BuildMainModule @binaryModuleParams {
Synopsis: Build xUnit tests
#>
task BuildXUnitTests @xUnitTestParams {
exec { dotnet publish -f $TestFramework -c $Configuration test }
exec { dotnet publish -f $targetFramework -c $Configuration test }
}

<#
Synopsis: Run the unit tests
#>
task RunTests BuildMainModule, BuildXUnitTests, {
Write-Verbose "Run tests targeting '$TestFramework' ..."
Start-TestRun -Configuration $Configuration -Framework $TestFramework
Write-Verbose "Run tests targeting $targetFramework ..."
Start-TestRun -Configuration $Configuration -Framework $targetFramework
}

<#
Expand All @@ -97,7 +88,7 @@ task CheckHelpContent -If $CheckHelpContent {
<#
Synopsis: Copy all of the files that belong in the module to one place in the layout for installation
#>
task LayoutModule BuildPolyfiller, BuildMainModule, {
task LayoutModule BuildMainModule, {
if (-not (Test-Path $targetDir -PathType Container)) {
New-Item $targetDir -ItemType Directory -Force > $null
}
Expand All @@ -115,17 +106,7 @@ task LayoutModule BuildPolyfiller, BuildMainModule, {
Set-Content -Path (Join-Path $targetDir (Split-Path $file -Leaf)) -Value (ConvertTo-CRLF $content) -Force
}

if (-not (Test-Path "$targetDir/netstd")) {
New-Item "$targetDir/netstd" -ItemType Directory -Force > $null
}
if (-not (Test-Path "$targetDir/net6plus")) {
New-Item "$targetDir/net6plus" -ItemType Directory -Force > $null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is code to handle loading of the polyfill assembly when the module gets loaded. That needs to be changed too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed a module interface file. Are there more?

}

Copy-Item "Polyfill/bin/$Configuration/netstandard2.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" "$targetDir/netstd" -Force
Copy-Item "Polyfill/bin/$Configuration/net6.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" "$targetDir/net6plus" -Force

$binPath = "PSReadLine/bin/$Configuration/netstandard2.0/publish"
$binPath = "PSReadLine/bin/$Configuration/$targetFramework/publish"
Copy-Item $binPath/Microsoft.PowerShell.PSReadLine.dll $targetDir
Copy-Item $binPath/Microsoft.PowerShell.Pager.dll $targetDir

Expand Down
21 changes: 2 additions & 19 deletions PSReadLine/OnImportAndRemove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,12 @@ public class OnModuleImportAndRemove : IModuleAssemblyInitializer, IModuleAssemb
{
public void OnImport()
{
AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;
// Module initialization - reserved for future use
}

public void OnRemove(PSModuleInfo module)
{
AppDomain.CurrentDomain.AssemblyResolve -= ResolveAssembly;
}

/// <summary>
/// Load the correct 'Polyfiller' assembly based on the runtime.
/// </summary>
private static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
if (args.Name != "Microsoft.PowerShell.PSReadLine.Polyfiller, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
{
return null;
}

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

return Assembly.LoadFrom(path);
// Module cleanup - reserved for future use
}
}
}
21 changes: 12 additions & 9 deletions PSReadLine/PSReadLine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@
<RootNamespace>Microsoft.PowerShell.PSReadLine</RootNamespace>
<AssemblyName>Microsoft.PowerShell.PSReadLine</AssemblyName>
<NoWarn>$(NoWarn);CA1416</NoWarn>
<AssemblyVersion>2.4.5.0</AssemblyVersion>
<FileVersion>2.4.5</FileVersion>
<InformationalVersion>2.4.5</InformationalVersion>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<FileVersion>3.0.0</FileVersion>
<InformationalVersion>3.0.0</InformationalVersion>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PowerShellStandard.Library" version="5.1.0" />
<PackageReference Include="Microsoft.CSharp" version="4.7.0" />
<PackageReference Include="Microsoft.PowerShell.Pager" version="1.0.0" />
<ProjectReference Include="..\Polyfill\Polyfill.csproj" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.4.13" />
<PackageReference Include="System.Management.Automation" Version="7.4.13">
<ExcludeAssets>contentFiles</ExcludeAssets>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.PowerShell.Pager" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
<None Include="PSReadLine.psd1" CopyToOutputDirectory="PreserveNewest" />
<None Include="PSReadLine.psm1" CopyToOutputDirectory="PreserveNewest" />
Expand Down
4 changes: 2 additions & 2 deletions PSReadLine/PSReadLine.psd1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@{
RootModule = 'PSReadLine.psm1'
NestedModules = @("Microsoft.PowerShell.PSReadLine.dll")
ModuleVersion = '2.4.5'
ModuleVersion = '3.0.0'
GUID = '5714753b-2afd-4492-a5fd-01d9e2cff8b5'
Author = 'Microsoft Corporation'
CompanyName = 'Microsoft Corporation'
Copyright = '(c) Microsoft Corporation. All rights reserved.'
Description = 'Great command line editing in the PowerShell console host'
PowerShellVersion = '5.1'
PowerShellVersion = '7.4'
FormatsToProcess = 'PSReadLine.format.ps1xml'
AliasesToExport = @()
FunctionsToExport = 'PSConsoleHostReadLine'
Expand Down
2 changes: 1 addition & 1 deletion PSReadLine/PSReadLine.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ function PSConsoleHostReadLine
$lastRunStatus = $?
Microsoft.PowerShell.Core\Set-StrictMode -Off
[Microsoft.PowerShell.PSConsoleReadLine]::ReadLine($host.Runspace, $ExecutionContext, $lastRunStatus)
}
}
Loading