我已在Powershell dll(C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ WindowsPowerShell \ 3.0 \ System.Management.Automation.dll)的引用中添加了;我还删除了该引用并打开了项目文件并添加到<Reference Include="System.Management.Automation />
中。但是,这些都不起作用,我总是得到以下错误:
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
namespace Powershell_Execution
{
class Program
{
static void Main(string[] args)
{
foreach (String str in PowerShell.Create().AddScript("Get-Process").AddCommand("Out-String").Invoke<String>())
{
Console.WriteLine(str);
}
Console.ReadLine();
}
}
}
有什么想法吗?我遇到的所有内容都只是添加了<Reference Include="System.Management.Automation />
,但这只会产生相同的运行时错误。