PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
482 stars 93 forks source link

Incorrect resource directories when run in VSCode Terminal #1459

Open dsolodow opened 10 months ago

dsolodow commented 10 months ago

Prerequisites

Steps to reproduce

VSCode 1.83.1 with PowerShell extension 2023.8.0, set to Windows PowerShell x64. $PSVersionTable shows: Name Value


PSVersion 5.1.19041.3633 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.19041.3633 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

When running Install-PSResource it installs into the Documents\PowerShell\Modules directory instead of Documents\WindowsPowerShell\Modules

Expected behavior

Running PSResource cmdlets under Windows PowerShell should save to the WindowsPowerShell module/script direcory.

install-psresource -name exchangeonlinemanagement -scope CurrentUser

it should install to Documents\WindowsPowerShell\Modules\ExchangeOnlineManagement

Actual behavior

install-psresource -name exchangeonlinemanagement -scope CurrentUser

it *actually* installed to Documents\PowerShell\Modules\ExchangeOnlineManagement

Running the same line from powershell.exe or a Windows PowerShell tab in Terminal behaves as expected.

Error details

No response

Environment data

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     1.0.0      Microsoft.PowerShell.PSResourceGet  {Find-PSResource, Get-InstalledPSResource, Get-PSResourceRepository, Get-PSScriptFileInfo...}

Key   : PSVersion
Value : 5.1.19041.3633
Name  : PSVersion

Key   : PSEdition
Value : Desktop
Name  : PSEdition

Key   : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0...}
Name  : PSCompatibleVersions

Key   : BuildVersion
Value : 10.0.19041.3633
Name  : BuildVersion

Key   : CLRVersion
Value : 4.0.30319.42000
Name  : CLRVersion

Key   : WSManStackVersion
Value : 3.0
Name  : WSManStackVersion

Key   : PSRemotingProtocolVersion
Value : 2.3
Name  : PSRemotingProtocolVersion

Key   : SerializationVersion
Value : 1.1.0.1
Name  : SerializationVersion

Visuals

Terminal: image

VS Code: image

dsolodow commented 10 months ago

It looks like the issue is with utils.cs lines 985-990. If I read it correctly, it's looking at host.version and saying "if greater than 6.0, PowerShell, if less than, Windows PowerShell". Since the VSCode PowerShell terminal returns the module version (2023.8.0) as it's host.version it's mis-interpreting it.

hbuckle commented 10 months ago

I think that'll be the same issue as #463 then

SydneyhSmith commented 10 months ago

@andyleejordan do you know what PowerShell api we can call?

dsolodow commented 10 months ago

The linked issue had a note that linked to what PowerShellEditorServices does (if that helps): https://github.com/PowerShell/PowerShellEditorServices/blob/main/src/PowerShellEditorServices/Utility/VersionUtils.cs

andyleejordan commented 9 months ago

@SydneyhSmith given the constraint that you've just got PSCmdlet...I'm not sure but am looking at it. @SeeminglyScience any bright ideas? It has access to SessionState so there should be a good programmatic way to go about this but I'm not finding it quickly. I don't think I would want to invoke a command to do it...I mean maybe you're best off doing the reflection call like we do 🙃

dsolodow commented 2 months ago

no luck with a fix on this yet?