Skip to content

PackageManagment binaries should be installed under \Modules\PackageManagement\ folder  #2347

Description

@jianyunt

Problem

It is observed that PowerShell core is loading assembles from its installed folder first (e.g. PowerShell\6.0.0.10) if exists, even if ipmo with a full path. For most cases, this behavior seems to be ok. However for the PackageManagement, we need to allow users to update the PackageManagement via install-module. The updated binaries will be installed under PowerShell\6.0.0.10\Modules\PackageManagement. But these updated assemblies won't get loaded because PowerShell loads the built-in PackageManagement assemblies first.

Proposed Solution

When packaging the next alpha release, PackageManagment binaries should be installed under PowerShell\6.0.0.10\Modules\PackageManagement\ folder instead of root PowerShell\6.0.0.10\ folder.

FYI:
OneGet assemblies including .dlls/.ni.dlls:

Microsoft.PackageManagement.ArchiverProviders
Microsoft.PackageManagement.CoreProviders
Microsoft.PackageManagement
Microsoft.PackageManagement.MetaProvider.PowerShell
Microsoft.PackageManagement.NuGetProvider
Microsoft.PowerShell.PackageManagement

Steps to reproduce

  1. Install https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.10/PowerShell_6.0.0.10-alpha.10-win10-x64.msi
  2. copy any binary , In my case, Microsoft.PackageManagement.dll, to C:\Program Files\PowerShell\6.0.0.10\Modules\PackageManagement
    or any folder such as C:\Program Files\PowerShell\6.0.0.10\Temp.
  3. ipmo "C:\Program Files\PowerShell\6.0.0.10\Modules\PackageManagement\Microsoft.PackageManagement.dll"
  4. You will see the C:\Program Files\PowerShell\6.0.0.10\Microsoft.PackageManagement.dll is imported.

Expected behavior

The assembly under C:\Program Files\PowerShell\6.0.0.10\Modules\PackageManagement\ should be loaded.

Actual behavior

Any assembly if exists under C:\Program Files\PowerShell\6.0.0.10, will get loaded first.

Environment data

PS C:\Program Files\PowerShell\6.0.0.10> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-alpha
WSManStackVersion              3.0
GitCommitId                    v6.0.0-alpha.10
CLRVersion
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
BuildVersion                   3.0.0.0
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSEdition                      Core

Activity

  1. kilasuit commented on Sep 23, 2016

    @kilasuit
    Collaborator

    This looks like it is the same for the other modules that are installed with v6.0.0.10 too so would need to be resolved for them as well.

  2. daxian-dbw commented on Sep 23, 2016

    @daxian-dbw
    Member

    This happens because when running Import-Module <path-to-foo.dll>, powershell first tries to load the assembly using its short name foo via Assembly.Load, and if that fails, it turns to LoadFrom with the file path (https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/ExecutionContext.cs#L1376).

    Therefore, for FullCLR powershell, Import-Module <path-to-foo.dll> would load the GAC'ed foo.dll if there is one:

    PS:1> Import-Module F:\temp\Microsoft.PowerShell.Commands.Diagnostics.dll
    PS:2> $m = Get-Module "Microsoft.PowerShell.Commands.Diagnostics"
    PS:3> $m.ImplementingAssembly.Location
    C:\windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Diagnostics\v4.0_3.0.0.0__31bf3856ad364e35\Microsoft.PowerShell.Commands.Diagnostics.dll
    

    For CoreCLR powershell, Import-Module <path-to-foo.dll> would load the foo.dll from $PSHome if there is one there, which is the described symptom in this issue.

  3. daxian-dbw commented on Sep 23, 2016

    @daxian-dbw
    Member

    At any rate, if we want any in-box module to be update-able, then it should not leave the original set of assemblies around after it's updated. So PackageManagement assemblies should be placed within the module folder, at least when we package and release powershell core.

  4. kilasuit commented on Sep 24, 2016

    @kilasuit
    Collaborator

    see #2350 which also has this similar issue and would correct this too

    At any rate, if we want any in-box module to be update-able, then it should not leave the original set of assemblies around after it's updated.

  5. HemantMahawar commented on Oct 28, 2016

    @HemantMahawar
    Contributor

    This issue was moved to PowerShell/PowerShellGet#41

  6. jianyunt commented on Oct 28, 2016

    @jianyunt
    ContributorAuthor

    can you help me understand why this is OneGet issue? If PowerShellCore can not change the behavior by loading the binaries from root, even if a user explicitly ask from other folder, "ipmo C:\Program Files\PowerShell\6.0.0.10\Modules\PackageManagement\Microsoft.PackageManagement.dll" for example, then at least should package them to Modules folder so modules are updatable. In this case, put them under \Modules\PackageManagement folder. Reopen it.

  7. added this to the milestone on Nov 2, 2016
  8. kilasuit commented on Dec 1, 2016

    @kilasuit
    Collaborator

    This seems to have been resolved in 6.0.0.13 with the binaries for PackageManagement being located correctly in C:\Program Files\PowerShell\6.0.0.13\Modules\PackageManagement\1.1.1.0\coreclr

  9. HemantMahawar commented on Dec 6, 2016

    @HemantMahawar
    Contributor

    Ryan Yates (@kilasuit) Thanks for the confirmation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions