I've created some .DLL's compiled using .NetCore 1.1. I now need to load them into Powershell and call their methods. Is this supported or do my DLL's need to be compiled using the full version of .Net?
Your .NET Core dlls won't run on standard out of the box windows only flavored powershell.
But! There is a .NET Core friendly version of powershell here: Powershell Core.
Powershell Core will run on Windows, Linux, and macOS, just as .NET Core was meant to run.
I came across this question when trying to do something similar. I succeeded in loading a .NET Core dll in the following way:
// You can use namespaces, but also paths
using assembly 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.4\System.Text.Json.dll'
// Specific for the static method I use in my example
$options = New-Object System.Text.Json.JsonSerializerOptions
// Use the Serialize method of the static class JsonSerializer
$jsonString = [System.Text.Json.JsonSerializer]::Serialize($device, $options);
I used System.Text.Json, but you can do this with any dll.
Source: Powershell 7 docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With