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 Microsoft.PowerShell.SDK
and System.Management.Automation
NuGet package in .Net Standard project but I keep getting this error:
System.IO.FileLoadException
HResult=0x80131040
Message=Could not load file or assembly'System.Management.Automation, Version=6.1.2.0, 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.