【发布时间】:2013-11-02 08:05:21
【问题描述】:
我正在尝试在 VS 2010 的 C# WinForms 项目中编译这个简单的代码:
using System.IO;
using System.IO.Compression;
string zipPath = @"c:\example\start.zip";
string extractPath = @"c:\example\extract";
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
{
entry.ExtractToFile(Path.Combine(extractPath, entry.FullName));
}
}
}
ZipFile Class 的描述告诉我需要添加System.IO.Compression.FileSystem 程序集。对不起这个问题,但它到底在哪里?它以 DLL 的形式出现吗?它不在 .NET 参考列表中,我确信我已经安装了 .NET Framework v.4.5。
编辑:谁想要在你的 VS 2010 项目中包含一个简单的 Zip 存档支持,我发现 this project 可以直接编译到你自己的项目中。非常干净和简单。
【问题讨论】:
-
您需要使用 VS 2012 才能使用 .NET 4.5。 VS 2010 不支持 4.5,并且该程序集仅在 4.5 中可用。
-
@Tim:嗯。所以微软希望我们购买 VS 2012 来使用 Zip 归档功能。我做对了吗?
-
@Tim:正是蒂姆。我们应该使用 .NET 4.5 来获得 Zip 功能。
-
我将跳过政治,但是是的,对于那些特定的类,您必须使用 Visual Studio 2012。 stackoverflow.com/questions/12390175/…。您可以使用 GZipStream 压缩和解压缩单个文件。如果您可以使用 GNU 许可证,您也可以使用 SharipZipLib:icsharpcode.net/opensource/sharpziplib。我们在 Chilkat Zip 库上也很幸运,但这不是免费的:chilkatsoft.com/zip-dotnet.asp。
-
@COOOOOfd : 请升级到 vs2012
标签: c# .net visual-studio-2010 .net-4.5