I am trying to create a .net standard 2.0 library that calls PowerShell commands and scripts using PowerShell classes (System.Management.Automation). I want to use this .Net Standard library in .Net Framework (4.7.2) project.
I have already tried using
System.Management.Automation NuGet package in .Net Standard project but I keep getting this error:
HResult=0x80131040 Message=Could not load file or assembly'System.Management.Automation, Version=126.96.36.199, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Sample Code in .Net Standard 2.0 Library project:
Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); PowerShell posh = PowerShell.Create(); posh.Runspace = runspace;
How can I achieve this? Any help is appreciated.
If you want to target .NET Standard, you should reference the
PowerShellStandard.Library nuget package
PowerShell Standard exposes only the API surface that overlaps between PowerShell 5.1 (.NET Framework) and PowerShell Core (.NET Core), so it'll work regardless of which edition you compile against.
User contributions licensed under CC BY-SA 3.0