我正在用C#构build一个应用程序,到目前为止它只是调用“get-process”powershell命令。
我编辑了csproj文件以包含System.Management.Automation
<ItemGroup> <Reference Include="System.Management.Automation" />
在本地运行时(Windows 8.1运行PowerShell版本4)可以工作。
在具有Powershell版本2的远程Windows 7计算机上运行时,该程序会引发exception
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.
它无法findSystem.Management.Automation版本= 3.0.0.0。 我曾经相信,这将适用于任何版本的Powershell,并引用本地版本
Get-Process cmdlet可以在PS V2上运行。
是否有可能停止强制版本3的系统pipe理自动化? 我读过你可以在app.config中做到这一点,但没有提到系统pipe理自动化。
感谢您的时间。
————————————————– —-编辑——————————————— –
我能够做到这一点,但将目标框架设置为.Net 3.5,但是这现在迫使PS V2。 有没有反正我可以针对本地版本的系统pipe理DLL,并使客户端使用该版本?
Powershell 2.0不包括System.Management.Automation V3。 System.Management.Automation由Windows Management Framework Core提供,而不是由.Net提供。 如果你有Powershell 2.0,你没有自动化3.0。 有关Powershell 2.0中提供哪些文件/程序集的列表,请访问以下站点:
Windows管理框架(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