❔ Powershell Cmdlet with C# Nuget packages. Can't find the Nuget assemblies when I run the module!
I have a .net 4.8 project that creates Powershell CmdLets as a dll file. Builds fine. When I try to run it (import the module in a PS 5 session) it complains "File Not Found" when it tries to use some assemblies that I have in the References. Specifically right now the missing assembly is System.Runtime.CompilerServices.Unsafe v 4.0.4.1. I really don't understand how assembly lookup works in a powershell environment. Any help is appreciated.
9 Replies
are you distributing the output of build or publish?
@maxrez
um I'm not totally sure how they distribute it. What I am doing is running
Import-Module
in the output directory (that contains all the DLLs)
then running the module
I gave up trying to make this work though
what I wound up doing was getting rid of all the nuget packages with "v7.0"
and System.Text.Json for instance and using Newtonsoft.Json
basically using much older nuget package versions that would not try to use newer versions of that dll
as a possible clue as to what was happening.. I downloaded the 4.0.4.1 version of that DLL into the build dir and after importing my module in PS, I did Add-Type
to manually load the older version of the *Unsafe Dll
this got rid of the error message for 4.0.4.1, but then I got an error message saying it couldnt find v6 of the DLL!
so basically my module was trying to use two differnt versions of the *Unsafe DLL (not sure why exactly)the output directory from what?
building or publishing?
I build the project containing Cmdlets which results in a DLL file in the /bin/debug directory. I then open a powershell prompt and run
Import-Module <dll name>
yeah so, try using the output of publish instead
if you're using the CLI tooling, that's
dotnet publish
in VS there should be a Publish option in the build menu I thinkalso, your module should have a manifest https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_module_manifests?view=powershell-7.3
about Module Manifests - PowerShell
Describes the settings and practices for writing module manifest files.
this is all for powershell v5
which is why i think im running into difficulties
you're compiling against Framework 4.8
so it should be fine
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.