2016-04-20 44 views
4

我在TeamCity Builds中使用簡單的PowerShell腳本。添加類型:無法添加類型。程序集'System.IO.Compression.FileSystem'找不到

它需要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加載程序集

任何幫助將不勝感激

+1

什麼PowerShell的版本是您使用?而且,更重要的是,PowerShell使用的.NET版本是什麼?也許你需要強制它使用.NET 4來成功加載這個庫。 – ForNeVeR

+0

我正在使用.NET版本v4.0.30319重寫powershell.exe.config。它顯示'System.IO.Compression.FileSystem'的GAC = true,但不能加載相同的程序集 –

回答

3

嘗試加載,而不是特定的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 
+0

太棒了!你能幫忙嗎? http://stackoverflow.com/questions/39801315/how-to-chain-commands-at-a-special-powershell-4-command-prompt –