Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
o-l-a-v opened this issue Mar 31, 2024 · 3 comments
Open
3 tasks done
Labels
Milestone

Comments

@o-l-a-v
Copy link
Contributor

o-l-a-v commented Mar 31, 2024

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:

# 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

@ThomasNieto
Copy link
Contributor

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.

@o-l-a-v
Copy link
Contributor Author

o-l-a-v commented Apr 1, 2024

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

else
{
// This package is not a PowerShell package (eg a resource from the NuGet Gallery).
installPath = _pathsToInstallPkg.Find(path => path.EndsWith("Modules", StringComparison.InvariantCultureIgnoreCase));
_cmdletPassedIn.WriteVerbose($"This resource is not a PowerShell package and will be installed to the modules path: {installPath}.");
isModule = true;
}

I don't understand that design decision. 🤔

@SydneyhSmith SydneyhSmith added Issue-Discussion Place for discussion about issue/feature/etc Needs-Triage and removed Needs-Triage labels Apr 3, 2024
@SydneyhSmith
Copy link
Collaborator

SydneyhSmith commented Apr 5, 2024

@SydneyhSmith SydneyhSmith added Issue-Bug Something isn't working Area-Install and removed Issue-Discussion Place for discussion about issue/feature/etc Needs-Triage labels Apr 5, 2024
@SydneyhSmith SydneyhSmith added this to the vNext milestone Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants