我正在尝试创建一个.net标准2.0库,该库使用PowerShell类(System.Management.Automation)调用PowerShell命令和脚本。我想在.Net Framework(4.7.2)项目中使用此.Net标准库。
我已经尝试在.Net Standard项目中使用Microsoft.PowerShell.SDK
和System.Management.Automation
NuGet程序包,但我一直收到此错误:
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)
.Net Standard 2.0库项目中的示例代码:
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
PowerShell posh = PowerShell.Create();
posh.Runspace = runspace;
我该如何实现?任何帮助表示赞赏。
答案 0 :(得分:1)
如果要定位.NET Standard,则应引用PowerShellStandard.Library
nuget程序包
PowerShell Standard仅公开在PowerShell 5.1(.NET Framework)和PowerShell Core(.NET Core)之间重叠的API表面,因此无论您针对哪个版本进行编译,它都将起作用。