【发布时间】:2019-06-25 07:39:51
【问题描述】:
我正在尝试创建一个 .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;
我怎样才能做到这一点?任何帮助表示赞赏。
【问题讨论】:
标签: c# powershell .net-framework-version .net-standard-2.0