PowerShell / PSResourceGet

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

PSResourceGet installs nuget.org packages like they were PowerShell packages #1612

Open o-l-a-v opened 6 months ago

o-l-a-v commented 6 months ago

Prerequisites

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

Visuals

No response

ThomasNieto commented 6 months ago

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

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

o-l-a-v commented 6 months ago

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. 🤔

SydneyhSmith commented 6 months ago

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