PowerShell / ConsoleGuiTools

Modules that mix PowerShell and GUIs/CUIs!
https://www.powershellgallery.com/packages/Microsoft.PowerShell.ConsoleGuiTools
MIT License
759 stars 52 forks source link

Requires `.net 7`; does it really need to? #226

Closed tig closed 8 months ago

tig commented 8 months ago

Prerequisites

Steps to reproduce

When running my CI scripts for F7History I'm getting

image

Import-Module: D:\a\_temp\bc1451cf-be26-4c21-a8ab-69d5323c81e0.ps1:7
Line |
   7 |  Import-Module Microsoft.PowerShell.ConsoleGuiTools -Verbose -Force
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Could not load file or assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral,
     | PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Error: Process completed with exit code 1.

This is because the current GitHub Action Runners are still using PowerShell 7.2 (which was built using .net 6 and ConsoleGuiTools is built with .net 7.

{
    "sdk": {
        "version": "7.0.401"
    }
}
<Project Sdk="Microsoft.NET.Sdk">
    <Import Project="..\..\GraphicalTools.Common.props" />
    <PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
    </PropertyGroup>

etc...

I did this here:

https://github.com/PowerShell/GraphicalTools/commit/4714dd4a8882ca52b3d6e0acfc9ce812cacdf452

After pulling the remainder of my hair out I figured the cause out and developed a workaround, which installs pwsh 7.3 in my GitHub Action runners. There's probably an easier way to make shell: pwsh use a newer version, but using dotnet tool install works cross platform.

    - name: HACK - Install Latest PowerShell (so we get v7.3+ that uses .net 7)
      shell: pwsh
      run: |
          dotnet tool install --global PowerShell
          $prependText = $HOME + "/.dotnet/tools"
          $filePath = $env:GITHUB_PATH
          $content = Get-Content -Path $filePath
          $newContent = $prependText + "`r`n" + $content
          $newContent | Set-Content -Path $filePath -Encoding utf8
          $newContent

This is a minor issue that will resolve itself once the GitHub runners are updated to use Powershell 7.3.x.

I've submitted an issue for GitHub Runners: https://github.com/actions/runner-images/issues/8754

Expected behavior

ConsoleGuiTools works on PS 7.2.x.

Actual behavior

ConsoleGuiTools fails on 7.2.x

Error details

No response

Environment data

na

Version

7.3.9

Visuals

No response