无法加载文件或程序集'System.Management.Automation,Version = 3.0.0.0

Mat*_*416 6 c# windows powershell

我正在用C#构建一个应用程序,到目前为止它只是调用"get-process"powershell命令.

我编辑了csproj文件以包含System.Management.Automation

<ItemGroup>
 <Reference Include="System.Management.Automation" />
Run Code Online (Sandbox Code Playgroud)

在本地运行时(Windows 8.1运行Powershell版本4)它可以工作.

在具有Powershell版本2的远程Windows 7计算机上运行时,该程序将引发异常

System.IO.FileNotFoundException: Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Run Code Online (Sandbox Code Playgroud)

它找不到System.Management.Automation Version = 3.0.0.0.我一直认为这适用于任何版本的Powershell并引用本地版本

cmdlet Get-Process适用于PS V2.

是否有可能停止强制执行系统管理自动化的第3版?我已经读过您可以在app.config中执行此操作,但没有参考系统管理自动化.

感谢您的时间.

-------------------------------------------------- ----编辑--------------------------------------------- -

我能够完成这项工作,但将Target框架设置为.Net 3.5,但是这会强制PS V2.反正我是否可以定位系统管理dll的本地版本并使客户端使用该版本?

Col*_*337 8

Powershell 2.0不包括System.Management.Automation V3.System.Management.Automation由Windows Management Framework Core提供,而不是.Net.如果你有Powershell 2.0,你就没有Automation 3.0.有关Powershell 2.0中提供的文件/程序集的列表,请访问以下站点:

Windows Management Framework(Windows PowerShell 2.0,WinRM 2.0和BITS 4.0)

通过在目标计算机上从Microsoft安装WMF 4.0升级到Powershell 4.0.

http://www.microsoft.com/en-us/download/details.aspx?id=40855

  • 需要发生两件事之一。要么为 2.0 程序集重写程序,要么升级程序集以使您的程序在本地运行。这是我所知道的仅有的两个选项:-/ (2认同)