I want to write PowerShell in C#. There is a useful link from red-gate.com which describes the steps for the process. The author uses the .Net Framework as Class library project. I have no problems with that, however, I would like to write my functions also for .Net Core in order to make them also cross-platform functional.
I created a new project with the target framework netcoreapp3.1
. When I install System.Management.Automation 7.1.2
I get the error:
Error NU1202 Package System.Management.Automation 7.1.2 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package System.Management.Automation 7.1.2 supports: net5.0 (.NETCoreApp,Version=v5.0)
I am confused with the supported .NETCoreApp v5.0
. With this link https://dotnet.microsoft.com/download there is .NET v5.0 and .NET Core 3.1. When I target net5.0
I get the error that the reference assemblies are not found but I installed the .NET 5.0 SDK.
C:\Users\Alex_P>dotnet --list-sdks
3.1.403 [C:\Program Files\dotnet\sdk]
5.0.201 [C:\Program Files\dotnet\sdk]
My question, how can I use System.Management.Automation
in a .NET Core (cross-platform project) to write PowerShell functions?