我看到以下奇怪的行为与Windows Powershell。
脚本1:
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipArchiveMode]::Update
输出:
PS C:\Users\Administrator> C:\Users\Administrator\Documents\Untitled1.ps1
Unable to find type [System.IO.Compression.ZipArchiveMode].
At C:\Users\Administrator\Documents\Untitled1.ps1:3 char:1
+ [System.IO.Compression.ZipArchiveMode]::Update
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.IO.Compression.ZipArchiveMode:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
脚本2:
Add-Type -AssemblyName System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::Open
[System.IO.Compression.ZipArchiveMode]::Update
输出:
PS C:\Users\Administrator> C:\Users\Administrator\Documents\Untitled1.ps1
OverloadDefinitions
-------------------
static System.IO.Compression.ZipArchive Open(string archiveFileName, System.IO.Compression.ZipArchiveMode mode)
static System.IO.Compression.ZipArchive Open(string archiveFileName, System.IO.Compression.ZipArchiveMode mode, System.Text.Encoding entryNameEncoding)
Update
为什么Script1无法加载[System.IO.Compression.ZipArchiveMode]::Update
?如何修复Script1以确保正确加载[System.IO.Compression.ZipArchiveMode]::Update
?
1条答案
按热度按时间55ooxyrt1#
您还需要加载
System.IO.Compression
程序集,而不仅仅是System.IO.Compression.FileSystem
: