Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading .NetCore DLL's in powershell

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?

like image 408
user1513388 Avatar asked Jul 06 '17 14:07

user1513388


2 Answers

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.

like image 123
Ogre71 Avatar answered Oct 08 '22 06:10

Ogre71


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

like image 33
vvasch Avatar answered Oct 08 '22 06:10

vvasch