加载System.Management.Automation程序集时出错

我正在开发一个运行PowerShell脚本的WPF应用程序。

string scriptPath = "/script/myscript.ps1"; Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); pipeline.Commands.AddScript(scriptPath); Collection results = pipeline.Invoke(); 

我添加了以下程序集。

 C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll 

但是当程序运行后出现exception;

无法加载文件或程序集’System.Management.Automation,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35’或其依赖项之一。 强名称validation失败。 (来自HRESULT的exception:0x8013141A)“:”System.Management.Automation,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35“} **

当我搜索这个错误时,我可以找到一些答案。 但那些对我来说并不清楚。 请指教。

最后我能够解决我的问题。 这就是我的所作所为;
打开我的.csproj文件
搜索System.Management.Automation参考。
将其替换为以下
这些步骤解决了我的问题

Interesting Posts