首页 > 解决方案 > 如何在 PowerShell 2.0 中加载 WinSCPnet.dll 程序集?(此程序集由比当前加载的运行时更新的运行时构建)

问题描述

我正在尝试WinSCPnet.dll在 PowerShell 中使用以下代码加载文件,但出现以下错误。

Set-Location "D:\WinSCP-5.17.10-Automation"
Add-Type -Path "WinSCPnet.dll"

Add-Type : 无法加载文件或程序集 'file:///D:\WinSCP-5.17.10-Automatio n\WinSCPnet.dll' 或其依赖项之一。此程序集由比当前加载的运行时更新的运行时构建,无法加载。
在 line:2 char:9
+ Add-Type <<<< -Path "WinSCPnet.dll"
+ CategoryInfo : NotSpecified: (:) [Add-Type], BadImageFormatExce ption
+ FullyQualifiedErrorId : System.BadImageFormatException,Microsoft.PowerShell。 Commands.AddTypeCommand

有没有其他方法可以在 PowerShell 2.0 中添加此程序集,如果不支持,是否有任何WinSCPnet.dll可用的支持 PowerShell 2.0?

标签: .netpowershellwinscpwinscp-net

解决方案


我认为问题不在于 PowerShell 2 本身。这是关于 PowerShell 加载的 .NET 框架版本。当前版本的 WinSCP .NET 程序集面向 .NET 4.0。您可能已经安装了该版本。您只需要配置 PowerShell 即可使用它。

有涵盖此内容的 WinSCP 文章:
https ://winscp.net/eng/docs/message_net_runtime_newer_than_currently_loaded

按照那里的建议,尝试:

set COMPLUS_version=v4.0.30319
powershell ...

推荐阅读