Skip to content

Using PowershellStandard to determine dlls to import to script module? #71

Open

Description

Hello,

Been trying to figure out how to do this.

Say I have a script module that wants to use Microsoft.Extensions.Configuration. This nuget package, targeted for .NET standard 2.0, has some expected dependencies such as Microsoft.Extensions.Primitives, but down the nuspec tree there are also things like System.Memory.

I want to write a script module but I need to find which assemblies I need to include. For instance, exclude System.Memory if it is available in the Powershell Standard, to keep the module small.

Is there a way to generate, say, a list of assemblies that are in the Powershell Standard section and be able to "blacklist" them out somehow?

Activity

  1. TylerLeonhardt commented on Oct 14, 2019

    @TylerLeonhardt
    Member

    It's a good question but it has a complicated answer. Ideally what you would do is go through all the dlls that are sitting in $PSHOME and all the dlls in the publish directory of your module and exclude the ones that are already in $PSHOME however, this gets tricky because if you target multiple versions of PowerShell, the dll list might be different.

    A perfect example of this is Newtonsoft.dll which exists in PowerShell Core, but not in Windows PowerShell. If you want users to also use your module in Windows PowerShell, then you also need to bundle Newtonsoft.dll.

    Ideally, we'd have some tooling to help out with this scenario... but we haven't had the time to do so.

  2. TylerLeonhardt commented on Oct 14, 2019

    @TylerLeonhardt
    Member
  3. JustinGrote commented on Oct 14, 2019

    @JustinGrote
    Author
  4. JustinGrote commented on Oct 15, 2019

    @JustinGrote
    Author

    TylerLeonhardt I made a pretty effective tool for this! It basically builds an empty dotnet project against the powershell standard with packagereferences to the required nuget packages, then copies over the DLLs.

    https://gist.github.com/JustinGrote/5daa3d02be2ff9e913ae6b2a0f96769b

    Todo still: Detect and resolve with assembly binding redirects if an older assembly exists natively. What I've run into most commonly: System.Runtime.CompilerServices.Unsafe

  5. JustinGrote commented on Apr 1, 2020

    @JustinGrote
    Author

    I would say this is still something that PowershellStandard should cover, as teams such as PSGet do not appear to be leveraging it and still using manual methods to pare down the assembly list
    https://github.com/PowerShell/PowerShellGet/issues/104#issuecomment-607433179

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

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions