无法使用 System.IO.Compression.FileSystem.dll [英] Unable to use System.IO.Compression.FileSystem.dll
问题描述
我正在尝试让这个 Powershell 代码工作:
I am trying to get this Powershell code to work:
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)
但是我收到以下错误:
Unable to find type [System.IO.Compression.FileSystem.ZipFile]. Make sure that the assembly that contains this type is loaded.
我曾尝试使用位于此处的其他 DLL:
I have tried using the other DLL located here:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.IO.Compression.FileSystem.dll
但是我仍然遇到同样的错误.
However I still get the same error.
如何正确导入这个库?
我已经尝试了以下所有方法,但都没有奏效:
I have tried all of the following, none of them worked:
[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"
推荐答案
原来我使用了不正确的命名空间.
Turns out I was using an incorrect namespace.
ZipFile
位于 System.IO.Compression
命名空间中,而程序集称为 System.IO.Compression.FileSystem.dll
.
ZipFile
is located in the System.IO.Compression
namespace, whereas the assembly is called System.IO.Compression.FileSystem.dll
.
即.它与加载程序集无关,我只需要使用正确的命名空间:
Ie. it had nothing to do with loading the assembly, I just need to use the correct namespace:
[System.IO.Compression.ZipFile]::CreateFromDirectory($startPath, $zipPath)
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipPath, $extractPath)
这篇关于无法使用 System.IO.Compression.FileSystem.dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!