调用Powershell相关类库的版本问题:Could not load file or assembly System.Management.Automation, Version=3.0.0.0

今天有一部分测试用例Fail了。

从Case的日志看都是PS检查不成功的原因,但是在自己的coding机器上面却无法重现类似场景,于是又跑到测试机器上面去调查。

在测试机器上面的调试发现这样的错误: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

由此确定是加载类库的版本不对导致的。

根据MSDN提供的信息,System.Management.Automation.dll是PowerShell的一个重要类库,该加载版本属于Powershell3.0,而由于测试机器上面都为PowerShell2.0的缘故测试的Cases就失败了。

三个Solutions:

1. 根据运行机器上面Powershell版本,使测试代码运行的时候动态加载引用,只需

a. 判断Powershell的版本:


PS C:\OpConsoleInstaller> get-host
Name             : ConsoleHost
Version          : 2.0
InstanceId       : 004d3b48-755e-416b-811a-8a3832115100
UI      

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值