PSResourceGet icon indicating copy to clipboard operation
PSResourceGet copied to clipboard

PSResourceGet installs nuget.org packages like they were PowerShell packages

Open o-l-a-v opened this issue 1 year ago • 3 comments

Prerequisites

  • [X] Write a descriptive title.
  • [X] Make sure you are able to repro it on the latest released version
  • [X] Search the existing issues.

Steps to reproduce

As you can add any nuget v2 and v3 repository to PSResourceGet, maybe it would be smart to validate whether packages are ment for PowerShell before installing?

Take NuGet.Versioning for instance, it installs to $env:PSModulePath as a PowerShell module, but can't be imported as a module.

Steps to reproduce:

# Register NuGet as a resource repository
Register-PSResourceRepository -Name 'NuGet' -Priority 60 -Uri 'https://api.nuget.org/v3/index.json'

# Find latest version of NuGet.Versioning from nuget.org
Find-PSResource -Repository 'NuGet' -Name 'NuGet.Versioning' | Format-List

# Install it
Install-PSResource -Scope 'CurrentUser' -Repository 'NuGet' -TrustRepository -Name 'NuGet.Versioning'

# Find it locally
Get-InstalledPSResource -Name 'NuGet.Versioning' | Format-List

# Try to import it - Does not work
Import-Module -Name 'NuGet.Versioning'

# One can add it as type though
## Find info for latest installed version
$NuGetVersioning = Get-InstalledPSResource -Name 'NuGet.Versioning' | Sort-Object -Property 'Version' -Descending | Select-Object -First 1
## Add type
Add-Type -Path ([System.IO.Path]::Combine($NuGetVersioning.'InstalledLocation','NuGet.Versioning',$NuGetVersioning.Version.ToString(),'lib','netstandard2.0','NuGet.Versioning.dll'))
## Test it
[NuGet.Versioning.NuGetVersion]'1.2.3'

Related comments:

Expected behavior

Validate whether a package is made for PowerShell. Tags? Content when decompressed?

Alternatively, do something else with non-PowerShell NuGet packages? Add to different path or something.

Actual behavior

Installs non-PowerShell resources as if they were modules.

Error details

No response

Environment data

  • Windows 11 23H2
  • Microsoft.PowerShell.PSResourceGet v1.0.3
  • PowerShell v7.4.1 x64

Visuals

No response

o-l-a-v avatar Mar 31 '24 09:03 o-l-a-v

Here are the two tags used in PSRG to denote if a NuGet package is a module or script.

  • PSModule
  • PSScript

The logic should be updated check packages on a repo and fail if either of those tags aren't found.

ThomasNieto avatar Apr 01 '24 14:04 ThomasNieto

This seems to be by design: If neither a script or a module => Install as module.

https://github.com/PowerShell/PSResourceGet/blob/abfbf4222ef9a4c170b42e9c77df801040c69937/src/code/InstallHelper.cs#L1060-L1067

I don't understand that design decision. 🤔

o-l-a-v avatar Apr 01 '24 20:04 o-l-a-v

We should be installing nupkgs to the nugetcache https://github.com/nuget/docs.microsoft.com-nuget/blob/main/docs/consume-packages/managing-the-global-packages-and-cache-folders.md#managing-the-global-packages-cache-and-temp-folders

SydneyhSmith avatar Apr 05 '24 17:04 SydneyhSmith