6

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?

1
  • 1
    PowerShell is based on the .NET Framework, not .NET Core. If you build your assembly against the appropriate netstandard profile (and its dependencies are also deployed), it should run on .NET Framework. If you build it explicitly as .NET Core only, it might not. Commented Jul 6, 2017 at 14:54

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

To add a DLL to a powershell script use the following code: Add-Type -Path "C:\locationOfDLL\mydll.dll". See if that works for accessing the dll as needed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.