我在TeamCity Builds中使用简单的PowerShell脚本。
它需要System.IO.Compression.FileSystem
,并且代理服务器已安装.NET 4.5.2。以下是安装的.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
这个 PowerShell 脚本中有以下代码行:
[Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem");
Add-Type -AssemblyName System.IO.Compression.FileSystem
在第二行执行时出现错误
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
奇怪的是,我预计在使用.NET 4.5.2时,PowerShell应该能够从GAC中加载程序集。任何帮助将不胜感激。
v4.0.30319
覆盖powershell.exe.config。它显示System.IO.Compression.FileSystem
的GAC=true,但无法加载相同的程序集。 - GeekzSG