[英]Add-Type: Cannot add type. The assembly 'System.IO.Compression.FileSystem' could not be found
I am using simple PowerShell script in TeamCity Builds.我在 TeamCity Builds 中使用了简单的 PowerShell 脚本。
It requires System.IO.Compression.FileSystem
and the agent has .NET 4.5.2 installed.它需要
System.IO.Compression.FileSystem
并且代理安装了 .NET 4.5.2。 Below are the .NET frameworks installed下面是安装的 .NET 框架
PSChildName Version Release Product
----------- ------- ------- -------
v2.0.50727 2.0.50727.5420
v3.0 3.0.30729.5420
Windows Communic... 3.0.4506.5420
Windows Presenta... 3.0.6920.5011
v3.5 3.5.30729.5420
Client 4.5.51209 379893 4.5.2
Full 4.5.51209 379893 4.5.2
Client 4.0.0.0
The PowerShell script has following line PowerShell 脚本具有以下行
[Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem");
Add-Type -AssemblyName System.IO.Compression.FileSystem
On the second line, the execution fails with error在第二行,执行失败并报错
Add-Type : Cannot add type. The assembly 'System.IO.Compression.FileSystem' could not be found.
At C:\BuildAgent\someFile.ps1:104 char:13
+ Add-Type <<<< -AssemblyName System.IO.Compression.FileSystem
+ CategoryInfo : ObjectNotFound: (System.IO.Compression.FileSystem:String) [Add-Type], Exception
+ FullyQualifiedErrorId : ASSEMBLY_NOT_FOUND,Microsoft.PowerShell.Commands.AddTypeCommand
Strange, but I expected that with .NET 4.5.2
, PowerShell should be able to load assembly from GAC
奇怪,但我预计使用
.NET 4.5.2
,PowerShell 应该能够从GAC
加载程序集
Any help will be appreciated任何帮助将不胜感激
尝试加载特定的 DLL:
Add-Type -Path C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IO.Compression.FileSystem\v4.0_4.0.0.0__b77a5c561934e089\System.IO.Compression.FileSystem.dll
LoadWithPartialName()
is obsolete'd, so avoid it when you can; LoadWithPartialName()
已过时,因此请LoadWithPartialName()
避免使用它; however since LoadWithPartialName()
is already working in your context, you could also use the Location property from the object that is returned to load the DLL.但是,由于
LoadWithPartialName()
已经在您的上下文中工作,您还可以使用返回的对象中的 Location 属性来加载 DLL。
if($PSVersionTable.PSVersion -lt '5.0'){
Add-Type -Path ([Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem")).Location;
}else{
Add-Type -AssemblyName System.IO.Compression.FileSystem
}
I had the exactly same error when running PowerShell script.运行 PowerShell 脚本时,我遇到了完全相同的错误。 I guess it was some collision of installed .Net version vs. PowerShell version.
我猜这是安装的 .Net 版本与 PowerShell 版本的冲突。 In my case helped me just to update PowerShell version to the newest one.
就我而言,它只是帮助我将 PowerShell 版本更新为最新版本。 Can be found here:
可以在这里找到:
https://www.microsoft.com/en-us/download/details.aspx?id=40855 https://www.microsoft.com/en-us/download/details.aspx?id=40855
尝试添加它(并删除最后一部分)Add-Type -AssemblyName System.IO.Compression
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.