diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 3badafcd..52fb5319 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -65,23 +65,7 @@ Additional references: ### Bootstrap, Build and Test -To build `PSReadLine` on Windows, Linux, or macOS, -you must have the following installed: - -* .NET Core SDK 2.1.802 or [a newer version](https://www.microsoft.com/net/download) -* The PowerShell modules `InvokeBuild` and `platyPS` - -The build script `build.ps1` can be used to bootstrap, build and test the project. - -* Bootstrap: `./build.ps1 -Bootstrap` -* Build: - * Targeting .NET 4.6.2 (Windows only): `./build.ps1 -Configuration Debug -Framework net462` - * Targeting .NET Core: `./build.ps1 -Configuration Debug -Framework net6.0` -* Test: - * Targeting .NET 4.6.2 (Windows only): `./build.ps1 -Test -Configuration Debug -Framework net462` - * Targeting .NET Core: `./build.ps1 -Test -Configuration Debug -Framework net6.0` - -After build, the produced artifacts can be found at `/bin/Debug`. +See the [Building](../README.md#building) section in README for details. ### Submitting Pull Request diff --git a/.pipelines/PSReadLine-Official.yml b/.pipelines/PSReadLine-Official.yml index 4aee66af..01d18522 100644 --- a/.pipelines/PSReadLine-Official.yml +++ b/.pipelines/PSReadLine-Official.yml @@ -114,7 +114,7 @@ extends: - pwsh: | Write-Host "PS Version: $($($PSVersionTable.PSVersion))" Set-Location -Path '$(repoRoot)' - .\build.ps1 -Configuration Release -Framework net462 + .\build.ps1 -Configuration Release displayName: Build env: # Set ob_restore_phase to run this step before '🔒 Setup Signing' step. @@ -166,7 +166,7 @@ extends: TargetFolder: $(ob_outputDirectory) - pwsh: | - $versionInfo = Get-Item "$(signSrcPath)\Microsoft.PowerShell.PSReadLine2.dll" | ForEach-Object VersionInfo + $versionInfo = Get-Item "$(signSrcPath)\Microsoft.PowerShell.PSReadLine.dll" | ForEach-Object VersionInfo $moduleVersion = $versionInfo.ProductVersion.Split('+')[0] $vstsCommandString = "vso[task.setvariable variable=ob_sdl_sbom_packageversion]${moduleVersion}" diff --git a/MockPSConsole/MockPSConsole.csproj b/MockPSConsole/MockPSConsole.csproj index 725855d7..cebd3941 100644 --- a/MockPSConsole/MockPSConsole.csproj +++ b/MockPSConsole/MockPSConsole.csproj @@ -4,21 +4,18 @@ Exe MockPSConsole MockPSConsole - net462;net6.0 + net472;net6.0 512 Program.manifest true - - - - + - + diff --git a/PSReadLine.build.ps1 b/PSReadLine.build.ps1 index 49a397c2..e245dfae 100644 --- a/PSReadLine.build.ps1 +++ b/PSReadLine.build.ps1 @@ -19,8 +19,8 @@ param( [ValidateSet("Debug", "Release")] [string]$Configuration = (property Configuration Release), - [ValidateSet("net462", "net6.0")] - [string]$Framework, + [ValidateSet("net472", "net6.0")] + [string]$TestFramework, [switch]$CheckHelpContent ) @@ -30,71 +30,58 @@ Import-Module "$PSScriptRoot/tools/helper.psm1" # Final bits to release go here $targetDir = "bin/$Configuration/PSReadLine" -if (-not $Framework) -{ - $Framework = if ($PSVersionTable.PSEdition -eq "Core") { "net6.0" } else { "net462" } +if (-not $TestFramework) { + $TestFramework = $IsWindows ? "net472" : "net6.0" } -Write-Verbose "Building for '$Framework'" -Verbose - 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/$Framework/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" + 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/$Framework/Microsoft.PowerShell.PSReadLine2.dll" + Outputs = "PSReadLine/bin/$Configuration/netstandard2.0/Microsoft.PowerShell.PSReadLine.dll" } $xUnitTestParams = @{ Inputs = { Get-ChildItem test/*.cs, test/*.json, test/PSReadLine.Tests.csproj } - Outputs = "test/bin/$Configuration/$Framework/PSReadLine.Tests.dll" -} - -$mockPSConsoleParams = @{ - Inputs = { Get-ChildItem MockPSConsole/*.cs, MockPSConsole/Program.manifest, MockPSConsole/MockPSConsole.csproj } - Outputs = "MockPSConsole/bin/$Configuration/$Framework/MockPSConsole.dll" + Outputs = "test/bin/$Configuration/$TestFramework/PSReadLine.Tests.dll" } <# Synopsis: Build the Polyfiller assembly #> -task BuildPolyfiller @polyFillerParams -If ($Framework -eq "net462") { - ## Build both "net462" and "net6.0" - exec { dotnet publish -f "net462" -c $Configuration Polyfill } - exec { dotnet publish -f "net6.0" -c $Configuration Polyfill } +task BuildPolyfiller @polyFillerParams { + exec { dotnet publish -c $Configuration -f 'netstandard2.0' Polyfill } + exec { dotnet publish -c $Configuration -f 'net6.0' Polyfill } } <# Synopsis: Build main binary module #> task BuildMainModule @binaryModuleParams { - exec { dotnet publish -f $Framework -c $Configuration PSReadLine } + exec { dotnet publish -c $Configuration PSReadLine\PSReadLine.csproj } } <# Synopsis: Build xUnit tests #> task BuildXUnitTests @xUnitTestParams { - exec { dotnet publish -f $Framework -c $Configuration test } -} - -<# -Synopsis: Build the mock powershell console. -#> -task BuildMockPSConsole @mockPSConsoleParams { - exec { dotnet publish -f $Framework -c $Configuration MockPSConsole } + exec { dotnet publish -f $TestFramework -c $Configuration test } } <# Synopsis: Run the unit tests #> -task RunTests BuildMainModule, BuildXUnitTests, { Start-TestRun -Configuration $Configuration -Framework $Framework } +task RunTests BuildMainModule, BuildXUnitTests, { + Write-Verbose "Run tests targeting '$TestFramework' ..." + Start-TestRun -Configuration $Configuration -Framework $TestFramework +} <# Synopsis: Check if the help content is in sync. @@ -128,35 +115,27 @@ task LayoutModule BuildPolyfiller, BuildMainModule, { Set-Content -Path (Join-Path $targetDir (Split-Path $file -Leaf)) -Value (ConvertTo-CRLF $content) -Force } - if ($Framework -eq "net462") { - if (-not (Test-Path "$targetDir/net462")) { - New-Item "$targetDir/net462" -ItemType Directory -Force > $null - } - if (-not (Test-Path "$targetDir/net6plus")) { - New-Item "$targetDir/net6plus" -ItemType Directory -Force > $null - } - - Copy-Item "Polyfill/bin/$Configuration/net462/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" "$targetDir/net462" -Force - Copy-Item "Polyfill/bin/$Configuration/net6.0/Microsoft.PowerShell.PSReadLine.Polyfiller.dll" "$targetDir/net6plus" -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 } - $binPath = "PSReadLine/bin/$Configuration/$Framework/publish" - Copy-Item $binPath/Microsoft.PowerShell.PSReadLine2.dll $targetDir + 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" + Copy-Item $binPath/Microsoft.PowerShell.PSReadLine.dll $targetDir Copy-Item $binPath/Microsoft.PowerShell.Pager.dll $targetDir if ($Configuration -eq 'Debug') { Copy-Item $binPath/*.pdb $targetDir } - if (Test-Path $binPath/System.Runtime.InteropServices.RuntimeInformation.dll) { - Copy-Item $binPath/System.Runtime.InteropServices.RuntimeInformation.dll $targetDir - } else { - Write-Warning "Build using $Framework is not sufficient to be downlevel compatible" - } - # Copy module manifest, but fix the version to match what we've specified in the binary module. $moduleManifestContent = ConvertTo-CRLF (Get-Content -Path 'PSReadLine/PSReadLine.psd1' -Raw) - $versionInfo = (Get-ChildItem -Path $targetDir/Microsoft.PowerShell.PSReadLine2.dll).VersionInfo + $versionInfo = (Get-ChildItem -Path $targetDir/Microsoft.PowerShell.PSReadLine.dll).VersionInfo $version = $versionInfo.FileVersion $semVer = $versionInfo.ProductVersion diff --git a/PSReadLine/OnImportAndRemove.cs b/PSReadLine/OnImportAndRemove.cs index 10f7000f..70208420 100644 --- a/PSReadLine/OnImportAndRemove.cs +++ b/PSReadLine/OnImportAndRemove.cs @@ -28,7 +28,7 @@ private static Assembly ResolveAssembly(object sender, ResolveEventArgs args) } string root = Path.GetDirectoryName(typeof(OnModuleImportAndRemove).Assembly.Location); - string subd = (Environment.Version.Major >= 6) ? "net6plus" : "net462"; + string subd = (Environment.Version.Major >= 6) ? "net6plus" : "netstd"; string path = Path.Combine(root, subd, "Microsoft.PowerShell.PSReadLine.Polyfiller.dll"); return Assembly.LoadFrom(path); diff --git a/PSReadLine/PSReadLine.csproj b/PSReadLine/PSReadLine.csproj index 7537ed98..72fc8fe8 100644 --- a/PSReadLine/PSReadLine.csproj +++ b/PSReadLine/PSReadLine.csproj @@ -3,30 +3,23 @@ Library Microsoft.PowerShell.PSReadLine - Microsoft.PowerShell.PSReadLine2 + Microsoft.PowerShell.PSReadLine $(NoWarn);CA1416 2.4.0.0 2.4.0 2.4.0-beta0 true - net462;net6.0 + netstandard2.0 true + false 9.0 - + - - - - - - - - - + diff --git a/PSReadLine/PSReadLine.psd1 b/PSReadLine/PSReadLine.psd1 index a9f201c0..d32db386 100644 --- a/PSReadLine/PSReadLine.psd1 +++ b/PSReadLine/PSReadLine.psd1 @@ -1,6 +1,6 @@ @{ RootModule = 'PSReadLine.psm1' -NestedModules = @("Microsoft.PowerShell.PSReadLine2.dll") +NestedModules = @("Microsoft.PowerShell.PSReadLine.dll") ModuleVersion = '2.4.0' GUID = '5714753b-2afd-4492-a5fd-01d9e2cff8b5' Author = 'Microsoft Corporation' diff --git a/Polyfill/Polyfill.csproj b/Polyfill/Polyfill.csproj index 86a62ad3..2cdccfbb 100644 --- a/Polyfill/Polyfill.csproj +++ b/Polyfill/Polyfill.csproj @@ -3,19 +3,19 @@ Microsoft.PowerShell.PSReadLine.Polyfiller 1.0.0.0 - net462;net6.0 + netstandard2.0;net6.0 true - + - + - + $(DefineConstants);LEGACY diff --git a/README.md b/README.md index 24d962a9..d1ab3d11 100644 --- a/README.md +++ b/README.md @@ -36,115 +36,34 @@ Some good resources about `PSReadLine`: - Ed Wilson (Scripting Guy) wrote a [series](https://devblogs.microsoft.com/scripting/tag/psreadline/) (2014-2015) on `PSReadLine`. - John Savill has a [video](https://www.youtube.com/watch?v=Q11sSltuTE0) (2021) covering installation, configuration, and tailoring `PSReadLine` to your liking. -## Installation +## Installation and Upgrading -There are multiple ways to install `PSReadLine`. +You will need the `1.6.0` or a higher version of [`PowerShellGet`](https://learn.microsoft.com/en-us/powershell/gallery/powershellget/install-powershellget) to install or upgrade to the latest prerelease version of `PSReadLine`. -### Install from PowerShellGallery (preferred) - -You will need the `1.6.0` or a higher version of [`PowerShellGet`](https://learn.microsoft.com/en-us/powershell/gallery/powershellget/install-powershellget) to install the latest prerelease version of `PSReadLine`. - -Windows PowerShell 5.1 ships an older version of `PowerShellGet` which doesn't support installing prerelease modules, -so Windows PowerShell users need to install the latest `PowerShellGet` (if not yet) by running the following commands from an elevated Windows PowerShell session: +PowerShell 6+ already has a higher version of `PowerShellGet` built-in. +However, Windows PowerShell 5.1 ships an older version of `PowerShellGet` which doesn't support installing prerelease modules. +So, Windows PowerShell users need to install the latest `PowerShellGet` (if not yet) by running the following commands from an elevated Windows PowerShell session: ```powershell -Install-Module -Name PowerShellGet -Force -Exit +Install-Module -Name PowerShellGet -Force; exit ``` -After installing `PowerShellGet`, you can get the latest prerelease version of `PSReadLine` by running +After installing `PowerShellGet`, you install or upgrade to the latest prerelease version of `PSReadLine` by running ```powershell -Install-Module PSReadLine -AllowPrerelease -Force +Install-Module PSReadLine -Repository PSGallery -Scope CurrentUser -AllowPrerelease -Force ``` If you only want to get the latest stable version, run: ```powershell -Install-Module PSReadLine +Install-Module PSReadLine -Repository PSGallery -Scope CurrentUser -Force ``` >[!NOTE] Prerelease versions will have newer features and bug fixes, but may also introduce new issues. -If you are using Windows PowerShell on Windows 10 or using PowerShell 6+, `PSReadLine` is already installed. -Windows PowerShell on the latest Windows 10 has version `2.0.0-beta2` of `PSReadLine`. -PowerShell 6+ versions have the newer prerelease versions of `PSReadLine`. - -### Install from GitHub (deprecated) - -With the preview release of PowerShellGet for PowerShell V3/V4, downloads from GitHub are deprecated. -We don't intend to update releases on GitHub, and may remove the release entirely from GitHub at some point. - -### Post Installation - -If you are using Windows PowerShell V5 or V5.1 versions, or using PowerShell 6+ versions, you are good to go and can skip this section. - -Otherwise, you need to edit your profile to import the module. -There are two profile files commonly used and the instructions are slightly different for each. -The file `C:\Users\[User]\Documents\WindowsPowerShell\profile.ps1` is used for all hosts (e.g. the `ISE` and `powershell.exe`). -If you already have this file, then you should add the following: - -```powershell -if ($host.Name -eq 'ConsoleHost') -{ - Import-Module PSReadLine -} -``` - -Alternatively, the file `C:\Users\[User]\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1` is for `powershell.exe` only. Using this file, you can simply add: - -```powershell -Import-Module PSReadLine -``` - -In either case, you can create the appropriate file if you don't already have one. - -## Upgrading - -When running one of the suggested commands below, be sure to exit all instances of `powershell.exe`, `pwsh.exe` or `pwsh`, -including those opened in `VSCode` terminals. - -Then, to make sure `PSReadLine` isn't loaded: -- _if you are on Windows_, run the suggested command below from `cmd.exe`, `powershell_ise.exe`, or via the `Win+R` shortcut; -- _if you are on Linux/macOS_, run the suggested command below from the default terminal (like `bash` or `zsh`). - - -If you are using the version of `PSReadLine` that ships with Windows PowerShell, -you need to run: `powershell -noprofile -command "Install-Module PSReadLine -Force -SkipPublisherCheck -AllowPrerelease"`. -Note: you will need to make sure [PowershellGet is updated](https://github.com/PowerShell/PSReadLine#install-from-powershellgallery-preferred) before running this command. - -If you are using the version of `PSReadLine` that ships with PowerShell 6+ versions, -you need to run: ` -noprofile -command "Install-Module PSReadLine -Force -SkipPublisherCheck -AllowPrerelease"`. - -If you've installed `PSReadLine` yourself from the PowerShell Gallery, -you can simply run: `powershell -noprofile -command "Update-Module PSReadLine -AllowPrerelease"` or -` -noprofile -command "Update-Module PSReadLine -AllowPrerelease"`, -depending on the version of PowerShell you are using. - -If you get an error like: - -```none -Remove-Item : Cannot remove item -C:\Users\{yourName}\Documents\WindowsPowerShell\Modules\PSReadLine\Microsoft.PowerShell.PSReadLine.dll: Access to the path -'C:\Users\{yourName}\Documents\WindowsPowerShell\Modules\PSReadLine\Microsoft.PowerShell.PSReadLine.dll' is denied. -``` - -or a warning like: - -```none -WARNING: The version '2.0.0' of module 'PSReadLine' is currently in use. Retry the operation after closing the applications. -``` - -Then you didn't kill all the processes that loaded `PSReadLine`. - ## Usage -To start using, just import the module: - -```powershell -Import-Module PSReadLine -``` - To use Emacs key bindings, you can use: ```powershell @@ -157,16 +76,19 @@ To view the current key bindings: Get-PSReadLineKeyHandler ``` -There are many configuration options, see the options to `Set-PSReadLineOption`. `PSReadLine` has help for it's cmdlets as well as an `about_PSReadLine` topic - see those topics for more detailed help. +There are many configuration options, see the options to `Set-PSReadLineOption`. +`PSReadLine` has help for its cmdlets as well as an `about_PSReadLine` topic - see those topics for more detailed help. -To set your own custom keybindings, use the cmdlet `Set-PSReadLineKeyHandler`. For example, for a better history experience, try: +To set your own custom keybindings, use the cmdlet `Set-PSReadLineKeyHandler`. +For example, for a better history experience, try: ```powershell Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward ``` -With these bindings, up arrow/down arrow will work like PowerShell/cmd if the current command line is blank. If you've entered some text though, it will search the history for commands that start with the currently entered text. +With these bindings, up arrow/down arrow will work like PowerShell/cmd if the current command line is blank. +If you've entered some text though, it will search the history for commands that start with the currently entered text. To enable bash style completion without using Emacs mode, you can use: @@ -200,7 +122,10 @@ Set-PSReadLineKeyHandler -Chord '"',"'" ` } ``` -In this example, when you type a single quote or double quote, there are two things that can happen. If the character following the cursor is not the quote typed, then a matched pair of quotes is inserted and the cursor is placed inside the the matched quotes. If the character following the cursor is the quote typed, the cursor is simply moved past the quote without inserting anything. If you use Resharper or another smart editor, this experience will be familiar. +In this example, when you type a single quote or double quote, there are two things that can happen. +If the character following the cursor is not the quote typed, then a matched pair of quotes is inserted and the cursor is placed inside the the matched quotes. +If the character following the cursor is the quote typed, the cursor is simply moved past the quote without inserting anything. +If you use `VSCode`, `Resharper`, or another smart editor, this experience will be familiar. Note that with the handler written this way, it correctly handles Undo - both quotes will be undone with one undo. @@ -211,10 +136,10 @@ See the public methods of `[Microsoft.PowerShell.PSConsoleReadLine]` to see what If you want to change the command line in some unimplmented way in your custom key binding, you can use the methods: ```powershell - [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState - [Microsoft.PowerShell.PSConsoleReadLine]::Insert - [Microsoft.PowerShell.PSConsoleReadLine]::Replace - [Microsoft.PowerShell.PSConsoleReadLine]::SetCursorPosition +[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState +[Microsoft.PowerShell.PSConsoleReadLine]::Insert +[Microsoft.PowerShell.PSConsoleReadLine]::Replace +[Microsoft.PowerShell.PSConsoleReadLine]::SetCursorPosition ``` ## Developing and Contributing @@ -226,26 +151,23 @@ Please see the [Contribution Guide][] for how to develop and contribute. To build `PSReadLine` on Windows, Linux, or macOS, you must have the following installed: -* .NET Core SDK 2.1.802 or [a newer version](https://www.microsoft.com/net/download) +* .NET 6.0 or [a newer version](https://www.microsoft.com/net/download) * The PowerShell modules `InvokeBuild` and `platyPS` The build script `build.ps1` can be used to bootstrap, build and test the project. * Bootstrap: `./build.ps1 -Bootstrap` -* Build: - * Targeting .NET 4.6.2 (Windows only): `./build.ps1 -Configuration Debug -Framework net462` - * Targeting .NET Core: `./build.ps1 -Configuration Debug -Framework net6.0` +* Build: `./build.ps1 -Configuration Debug` * Test: - * Targeting .NET 4.6.2 (Windows only): `./build.ps1 -Test -Configuration Debug -Framework net462` - * Targeting .NET Core: `./build.ps1 -Test -Configuration Debug -Framework net6.0` + * Targeting .NET 4.7.2 (Windows only): `./build.ps1 -Test -Configuration Debug -Framework net472` + * Targeting .NET 6.0: `./build.ps1 -Test -Configuration Debug -Framework net6.0` After build, the produced artifacts can be found at `/bin/Debug`. + In order to isolate your imported module to the one locally built, be sure to run `pwsh -NonInteractive -NoProfile` to not automatically load the default PSReadLine module installed. Then, load the locally built PSReadLine module by `Import-Module /bin/Debug/PSReadLine/PSReadLine.psd1`. -[Contribution Guide]: https://github.com/PowerShell/PSReadLine/blob/master/.github/CONTRIBUTING.md - ## Change Log The change log is available [here](https://github.com/PowerShell/PSReadLine/blob/master/PSReadLine/Changes.txt). @@ -254,8 +176,6 @@ The change log is available [here](https://github.com/PowerShell/PSReadLine/blob PSReadLine is licensed under the [2-Clause BSD License][]. -[2-Clause BSD License]: https://github.com/PowerShell/PSReadLine/blob/master/License.txt - ## Code of Conduct Please see our [Code of Conduct](.github/CODE_OF_CONDUCT.md) before participating in this project. @@ -263,3 +183,6 @@ Please see our [Code of Conduct](.github/CODE_OF_CONDUCT.md) before participatin ## Security Policy For any security issues, please see our [Security Policy](.github/SECURITY.md). + +[Contribution Guide]: https://github.com/PowerShell/PSReadLine/blob/master/.github/CONTRIBUTING.md +[2-Clause BSD License]: https://github.com/PowerShell/PSReadLine/blob/master/License.txt diff --git a/appveyor.yml b/appveyor.yml index 0caf57ba..e989afe0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -17,10 +17,10 @@ install: build_script: - pwsh: | - ./build.ps1 -Configuration Release -Framework net462 + ./build.ps1 -Configuration Release test_script: - - pwsh: ./build.ps1 -Test -Configuration Release -Framework net462 + - pwsh: ./build.ps1 -Test -Configuration Release -Framework net472 artifacts: - path: .\bin\Release\PSReadLine.zip diff --git a/build.ps1 b/build.ps1 index bb41830b..481f2a27 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,3 +1,5 @@ +#Requires -Version 7.4 + <# .SYNOPSIS A script that provides simple entry points for bootstrapping, building and testing. @@ -7,14 +9,14 @@ PS > .\build.ps1 -Bootstrap Check and install prerequisites for the build. .EXAMPLE - PS > .\build.ps1 -Configuration Release -Framework net462 - Build the main module with 'Release' configuration and targeting 'net462'. + PS > .\build.ps1 -Configuration Release + Build the main module with 'Release' configuration targeting 'netstandard2.0'. .EXAMPLE PS > .\build.ps1 - Build the main module with the default configuration (Debug) and the default target framework (determined by the current session). + Build the main module with the default configuration (Debug) targeting 'netstandard2.0'. .EXAMPLE PS > .\build.ps1 -Test - Run xUnit tests with the default configuration (Debug) and the default target framework (determined by the current session). + Run xUnit tests with the default configuration (Debug) and the default target framework (net472 on Windows or net6.0 otherwise). .PARAMETER Clean Clean the local repo, but keep untracked files. .PARAMETER Bootstrap @@ -24,23 +26,35 @@ .PARAMETER Configuration The configuration setting for the build. The default value is 'Debug'. .PARAMETER Framework - The target framework for the build. - When not specified, the target framework is determined by the current PowerShell session: - - If the current session is PowerShell Core, then use 'netcoreapp3.1' as the default target framework. - - If the current session is Windows PowerShell, then use 'net462' as the default target framework. + The target framework when testing: + - net472: run tests with .NET Framework + - net6.0: run tests with .NET 6.0 + When not specified, the target framework is determined by the current OS platform: + - use 'net472' on Windows + - use 'net6.0' on Unix platforms #> -[CmdletBinding()] +[CmdletBinding(DefaultParameterSetName = 'default')] param( + [Parameter(ParameterSetName = 'cleanup')] [switch] $Clean, + + [Parameter(ParameterSetName = 'bootstrap')] [switch] $Bootstrap, + + [Parameter(ParameterSetName = 'test')] [switch] $Test, + + [Parameter(ParameterSetName = 'test')] [switch] $CheckHelpContent, - [ValidateSet("Debug", "Release")] - [string] $Configuration = "Debug", + [Parameter(ParameterSetName = 'test')] + [ValidateSet("net472", "net6.0")] + [string] $Framework, - [ValidateSet("net462", "net6.0")] - [string] $Framework + [Parameter(ParameterSetName = 'default')] + [Parameter(ParameterSetName = 'test')] + [ValidateSet("Debug", "Release")] + [string] $Configuration = "Debug" ) # Clean step @@ -48,10 +62,11 @@ if ($Clean) { try { Push-Location $PSScriptRoot git clean -fdX - return } finally { Pop-Location } + + return } Import-Module "$PSScriptRoot/tools/helper.psm1" @@ -78,7 +93,7 @@ if (-not (Get-Module -Name InvokeBuild -ListAvailable)) { $buildTask = if ($Test) { "RunTests" } else { "ZipRelease" } $arguments = @{ Task = $buildTask; Configuration = $Configuration } -if ($Framework) { $arguments.Add("Framework", $Framework) } +if ($Framework) { $arguments.Add("TestFramework", $Framework) } if ($CheckHelpContent) { $arguments.Add("CheckHelpContent", $true) } Invoke-Build @arguments diff --git a/test/PSReadLine.Tests.csproj b/test/PSReadLine.Tests.csproj index 465743ec..34598cbe 100644 --- a/test/PSReadLine.Tests.csproj +++ b/test/PSReadLine.Tests.csproj @@ -5,7 +5,7 @@ library UnitTestPSReadLine PSReadLine.Tests - net462;net6.0 + net472;net6.0 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} False @@ -14,28 +14,24 @@ 9.0 - - - - - + - + - - - + + + all runtime; build; native; contentfiles; analyzers - - + +