无法使用System.IO.Compression.FileSystem.dll

Bac*_*ave 3 powershell zip

我试图让这个Powershell代码工作:

     Add-Type -Path 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.IO.Compression.FileSystem.dll'
     $startPath = "D:\nade\CBA\Zip\StartPath"
     $zipPath = "D:\nade\CBA\Zip\result.zip"
     $extractPath = "D:\nade\CBA\Zip\Extract"
     [System.IO.Compression.FileSystem.ZipFile]::CreateFromDirectory($startPath, $zipPath)
     [System.IO.Compression.FileSystem.ZipFile]::ExtractToDirectory($zipPath, $extractPath)
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

Unable to find type [System.IO.Compression.FileSystem.ZipFile]. Make sure that the assembly that contains this type is loaded.
Run Code Online (Sandbox Code Playgroud)

我尝试使用此处的其他DLL:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.IO.Compression.FileSystem.dll
Run Code Online (Sandbox Code Playgroud)

但是我仍然得到同样的错误.

如何正确导入此库?

编辑:我已经尝试了以下所有,但没有一个工作:

[System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem")
Add-Type -Path 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.IO.Compression.FileSystem.dll'
Add-Type -Path 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.IO.Compression.FileSystem.dll'
Add-type -AssemblyName "System.IO.Compression.FileSystem"
Run Code Online (Sandbox Code Playgroud)

Bac*_*ave 6

结果我使用了不正确的命名空间.

ZipFile位于System.IO.Compression命名空间中,而程序集则被调用System.IO.Compression.FileSystem.dll.

IE浏览器.它与加载程序集无关,我只需要使用正确的命名空间:

     [System.IO.Compression.ZipFile]::CreateFromDirectory($startPath, $zipPath)
     [System.IO.Compression.ZipFile]::ExtractToDirectory($zipPath, $extractPath)
Run Code Online (Sandbox Code Playgroud)


Daa*_*aap 5

我遇到了类似的错误,但无法让它工作(Windows Server 2008R2)。安装.NET 4.5和Powershell 3.0(在一些论坛中找到)后它仍然无法工作。它只有在我添加这两行后才起作用:

Add-Type -assembly "System.IO.Compression" Add-Type -assembly "System.IO.Compression.Filesystem"