Skip to content

Commit

Permalink
Add pre-build PowerShell version check (#14947)
Browse files Browse the repository at this point in the history
Two PowerShell scripts were added so that developers new to the project
know if they have the wrong version of PowerShell installed.

When first building Terminal, it would continuously fail, and I didn't
really know why. I'm new to both this project and to open source, so
when I saw an error message about "pwsh.exe" not being found I was
confused and didn't know what went wrong. What I didn't know is that
Windows PowerShell and PowerShell Core had different names for
their .exe files, and since I had the latest version of Windows
PowerShell installed, I figured that I was completely set. So, once I
realized that Windows PowerShell (what I had installed) is
powershell.exe and PowerShell Core (what I needed to have installed) is
pwsh.exe, I downloaded PowerShell Core, and it built without issue. So,
in order to help other newbies, I made two scripts, `CheckPSVersion` and
`WindowsCheckPSVersion`, which make sure that PowerShell Core 7.0.0+ is
installed, outputting an error telling the developer to download Core
7.0.0+ if they have Windows PowerShell but not Core. These scripts are
run pre-build courtesy of `Microsoft.Terminal.Settings.ModelLib.vcxproj`

## Validation Steps Performed
Building with both Windows PowerShell and PowerShell core: builds
perfectly, no issues.
Building with Windows PowerShell but not PowerShell core: build fails,
but a nice error prints out that reminds the user to download the
correct version of PowerShell core.

Closes #14797
  • Loading branch information
Smeyer025 authored Mar 31, 2023
1 parent e6a3fa8 commit 0105807
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@
<Import Project="$(OpenConsoleDir)src\cppwinrt.build.post.props" />
<Import Project="$(OpenConsoleDir)src\common.nugetversions.targets" />

<!-- PowerShell version check, outputs error if the wrong version is installed. -->
<Target Name="_WindowsPowershellVersionCheck" BeforeTargets="BeforeClCompile">
<Exec Command="powershell.exe -NoProfile -ExecutionPolicy Unrestricted &quot;$(OpenConsoleDir)\tools\WindowsCheckPSVersion.ps1&quot;" />
</Target>
<Target Name="_PowershellVersionCheck" BeforeTargets="BeforeClCompile">
<Exec Command="pwsh.exe -NoProfile -ExecutionPolicy Unrestricted &quot;$(OpenConsoleDir)\tools\CheckPSVersion.ps1&quot;" />
</Target>
<!-- This target will take our defaults.json and stamp it into a .h file that
we can include in the code directly. This way, we don't need to worry about
failing to load the default settings at runtime. -->
Expand Down
4 changes: 4 additions & 0 deletions tools/CheckPSVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if($PSVersionTable.PSVersion.Major -lt 7){
Write-Error "Incorrect version of PowerShell installed.`nMake sure you have at least PowerShell Core 7.0.0."
Exit 1
}
3 changes: 3 additions & 0 deletions tools/WindowsCheckPSVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if(-not (Get-Command "pwsh.exe" -ErrorAction SilentlyContinue)){
Write-Error "Incorrect version of PowerShell installed.`nMake sure you have at least PowerShell Core 7.0.0."
}

0 comments on commit 0105807

Please sign in to comment.