Flo*_*res 6 .net c# powershell
所以..非常奇怪的问题.
使用VS2015和.net 4.52
我开发了这个C#powershell代码,它正在运行一个脚本并捕获输出.像这样:
using (PowerShell powerShellInstance = PowerShell.Create())
{
powerShellInstance.AddScript(scriptContents);
Collection<PSObject> PSOutput = powerShellInstance.Invoke();
if (powerShellInstance.Streams.Information.Count > 0)
{
foreach (var item in powerShellInstance.Streams.Information)
{
//do something with info
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
编译和运行(在Windows 10 pro机器上),没有问题.
直到我得到一台新机器(Surface pro 4,所以也是windows 10 pro)并尝试编译代码,我收到此错误:
'PSDataStreams'不包含'Information'的定义,也没有接受'PSDataStreams'类型的第一个参数的扩展方法'Information'(你是否缺少using指令或汇编引用?)
这都是基于TFS的,所以我确定它是相同的代码.
如果我在两台机器上进行定义,问题就变得很明显了:
所以,我注释掉了不编译代码并运行它,看看运行时发生了什么:
那么财产就在那里..有人对此有一个很好的解释吗?
顺便说一句:msdn文档没有提到信息属性..
您可能System.Management.Automation.dll在Surface Pro上引用了错误的程序集版本.
在我的Windows 10 Pro安装(从Windows 8.1升级)上,我有两个版本,每个GAC一个:
在图片中选择的那个是"旧的",存在于旧的GAC(C:\windows\assembly)中,并使用文件版本6.1.7600.16385进行标识.
另一个(包含正确版本PSDataStreams并公开Information流)存在于C:\Windows\Microsoft.NET\assembly文件版本10.0.10240.16384中.
| 归档时间: |
|
| 查看次数: |
898 次 |
| 最近记录: |