【发布时间】:2017-02-27 14:46:38
【问题描述】:
我正在尝试使用 ZipFile 中包含的功能,但无法包含命名空间。我有一个项目并成功引用了System.IO.Compression,但是当我尝试引用System.IO.Compression.FileSystem时,我得到:
命名空间名称“FileSystem”的类型在命名空间“System.IO.Compression”中不存在
当我尝试拨打 ZipFile 时,我得到了
名称 'ZipFile 在当前上下文中不存在
我正在运行.net 4.5.2,所以我应该可以访问这些功能。我不知道发生了什么,因为似乎我做的一切都是正确的。
我尝试在 Visual Studio 中使用 Add Reference 添加这两个引用,Visual Studio 将其包含在 References 文件夹中,但我无法在我的处理程序中使用它。
任何帮助都会很棒,谢谢!
我目前的使用指令:
using System.IO.Compression;
我也在我的项目中引用了System.IO.Compression.FileSystem.dll,所以这个错误没有任何意义。
尝试使用 ZipFile:
string startPath = @"c:\example\start";
string zipPath = @"c:\example\result.zip";
string extractPath = @"c:\example\extract";
ZipFile.CreateFromDirectory(startPath, zipPath);
ZipFile.ExtractToDirectory(zipPath, extractPath);
The directories within the variables don't exist but that doesn't matter because ZipFile isn't even being found.
使用指令:
我的项目和参考资料:
【问题讨论】:
-
using 指令与引用不同。如果成功添加了引用(引用上没有警告图标,并且错误列表中没有警告),您可以使用 using 指令从您添加引用的项目中的引用程序集中导入命名空间。
-
感谢您非常有帮助的评论...我已经尝试了几乎所有关于 SO 的“解决方案”,这里似乎没有任何解决方案。我是这种语言的新手,根据我的理解,它应该像引用和使用它一样简单。
-
不要粗鲁,但你甚至读过这个问题吗?我已经在我的项目中引用了
System.IO.Compression.FileSystem.dll。 -
我是
using System.IO.Compression,然后在我的引用中引用了 dll。我看不出这有什么不妥... -
@CodeCaster 通过为该项目创建一个新的处理程序解决了这个问题。
标签: c# asp.net .net .net-4.0 .net-4.5