Skip to content

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

Open
@o-l-a-v

Description

@o-l-a-v

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • 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:

# Assets
$Repo = [ordered]@{
    'Name' = [string] 'NuGetv3'
    'Uri'  = [string] 'https://api.nuget.org/v3/index.json'
}


# Register NuGet as a resource repository
Register-PSResourceRepository -Name $Repo.'Name' -Priority 60 -ApiVersion 'V3' -Uri $Repo.'Uri'


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


# Install it
Install-PSResource -Repository $Repo.'Name' -TrustRepository -Scope 'CurrentUser' -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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions