www.91084.com

GVKun编程网logo

我在“ System.IO.Compression”命名空间中找不到“ ZipFile”类(未找到命名空间)

22

此处将为大家介绍关于我在“System.IO.Compression”命名空间中找不到“ZipFile”类的详细内容,并且为您解答有关未找到命名空间的相关问题,此外,我们还将为您介绍关于.net–My

此处将为大家介绍关于我在“ System.IO.Compression”命名空间中找不到“ ZipFile”类的详细内容,并且为您解答有关未找到命名空间的相关问题,此外,我们还将为您介绍关于.net – My.Computer.FileSystem和System.IO.File之间究竟有什么区别、asp.net – system.web.compilation.debug与system.codedom.compilers.compiler.compilerOptions / define:Debug = True、c – configure:error:找不到boost.filesystem库、c# – System.IO.Compression在ASP.NET VNext中完整的CLR的有用信息。

本文目录一览:

我在“ System.IO.Compression”命名空间中找不到“ ZipFile”类(未找到命名空间)

我在“ System.IO.Compression”命名空间中找不到“ ZipFile”类(未找到命名空间)

我不能在名称空间“ System.IO.Compression”中使用“ Zipfile”类,我的代码是:

using System;using System.IO;using System.IO.Compression;namespace ConsoleApplication{    class Program    {        static void Main(string[] args)        {            string startPath = @"c:\example\start";            string zipPath = @"c:\example\result.zip";            string extractPath = @"c:\example\extract";            ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest,true);            ZipFile.ExtractToDirectory(zipPath, extractPath);        }    }}

错误是:

名称“ zipfile”在当前上下文中不存在

我该如何解决?

答案1

小编典典

您需要添加对程序集“ System.IO.Compression.FileSystem.dll”的dll引用-并确保您使用的是.NET
4.5(因为在早期框架中不存在)。

有关信息,您可以从MSDN中找到程序集和.NET版本。

.net – My.Computer.FileSystem和System.IO.File之间究竟有什么区别

.net – My.Computer.FileSystem和System.IO.File之间究竟有什么区别

My.Computer.FileSystem和System.IO.File命名空间中存在大量重复的功能.

那究竟是什么区别:

My.Computer.FileSystem.copyFile(source,dest,True)

和:

System.IO.File.copy(source,True)

是否存在性能差异?什么是每个人对哪些具有阅读能力优势的看法?我个人使用My.Computer命名空间,但这只是习惯.

我的.*只是为VB.NET实现的一组Facade模式类,包含常见的System.IO *(和其他)操作.由于你经历了一个额外的抽象层,所以有一个非常微小的性能损失,但你必须决定它是否值得优化.我建议使用对你和你店里的其他人有意义的方式.

如果使用.NET Reflector检查My.Computer.FileSystem.copyFile的代码,您将看到该方法包装了许多System.IO类,例如File和Directory,尤其是File类的copy,Move和Delete方法.片段:

'lots of other code snipped out for brevity and to show the use of System.IO classes...

Directory.CreateDirectory(FileSystem.GetParentPath(str))

   'snip

    If 
       ' snip
    Else
        File.Delete(str)
        File.Move(path,str)
    End If
Else
    File.Move(path,str)
End If
End Sub

asp.net – system.web.compilation.debug与system.codedom.compilers.compiler.compilerOptions / define:Debug = True

asp.net – system.web.compilation.debug与system.codedom.compilers.compiler.compilerOptions / define:Debug = True

当我将ASP.NET Web应用程序部署到生产环境时,我使用配置转换从< compilation>中删除debug =“true”.但是,就在今天我注意到web.config中的另一个部分如下所示:
<system.codedom>
    <compilers>
        <compiler compilerOptions="/define:Debug=True" />
    </compilers>
</system.codedom>

这是什么?事实是,那就是打败了从< compilation>中删除它的目的吗?如果我删除上面显示的属性会怎样?

解决方法

Is the fact that that’s there defeating the purpose
of removing it from <compilation>

从MSDN C# Compiler Options起
要打开调试,编译器上的标志是/ debug而不是/ define:Debug = True

/debug : Instruct the compiler to emit debugging information.
/define : Defines preprocessor symbols.

因此,当您定义Debug = True时,您只能将此情况设为true:

#if DEBUG == true
// Compile what is inside here !
#endif

/ define:Debug = True不会添加任何其他调试信息,除非您使用上述代码手动包含它们.

测试页面

我使用以下代码进行测试,看看发生了什么.

txtDebug.Text = HttpContext.Current.IsDebuggingEnabled.ToString();

    #if DEBUG
    txtDebug.Text +=  "<br>defined Debug is on";
    #endif
    #if DEBUG == true
    txtDebug.Text +=  "<br>defined Debug = true is on";
    #endif

结果1

现在,如果debug =“false”并且使用compilerOptions =“/ define:Debug = True”,结果是

false
defined Debug = true is on

结果2

如果debug =“true”和compilerOptions =“/ define:Debug = True”结果是

true
defined Debug is on
defined Debug = true is on

结果3

现在我再做一次测试,我在web.config上添加了这一行

<compiler language="c#;cs;csharp" extension=".cs" 
    compilerOptions="/define:Debug=True /D:DEBUG,TESTFLAG" 
   type="Microsoft.CSharp.CSharpCodeProvider,System,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" 
       warningLevel="4" />

结果是debug = false

False (debug is false)
defined Debug is on (but the defined DEBUG Now is runs)
defined Debug = true is on (This is also runs)
test flag (but the defined extra flag is also runs)

MSDN

看看MSDN for the /define (Preprocessor Definition)我看那个宣言

/define:Debug=True

只适用于这种代码的情况

#if DEBUG == true
txtDebug.Text +=  "<br>defined Debug = true is on";
#endif

c – configure:error:找不到boost.filesystem库

c – configure:error:找不到boost.filesystem库

所以我试图通过这个github安装ncmpcpp,第一步是运行sh autogen.sh脚本.我遇到了一些丢失的库等等,但我已经能够安装它们并继续进行到现在为止.我已经做了一些搜索并安装了一些我认为有助于修复它的东西,但无济于事.

sudo apt-get install libboost1.55-all-dev

sudo apt-get install libboost-system-dev

sudo apt-get install libboost-system1.54-dev

sudo apt-get install libboost1.54-dev

sudo apt-get install libboost-filesystem-dev

sudo apt-get install libboost-filesystem-dev libboost-thread-dev

真相是我对Boost不了解或者我缺少自己解决的问题.

这是问题的开始:

checking for boost/filesystem.hpp… yes

checking for main in -lboost_filesystem-mt… no

configure: error: no boost.filesystem library found

编辑:以下是config.log文件中’-lboost_filesystem-mt’的周围行.

configure:15510: checking for main in -lboost_filesystem-mt

configure:15529: g++ -o conftest -g -O2 -std=c++0x conftest.cpp -lboost_filesystem-mt >&5

/usr/bin/ld: cannot find -lboost_filesystem-mt

collect2: error: ld returned 1 exit status

configure:15529: $? = 1

configure: Failed program was:

| /* confdefs.h */

…然后继续描述confdefs.h文件.

解决方法:

从configure.ac中删除这些链接(“设置增强环境”部分):

AS_IF([test -z "${BOOST_LIB_SUFFIX+x}"], [BOOST_LIB_SUFFIX=-mt])
AC_ARG_VAR([BOOST_LIB_SUFFIX], [Boost library name suffix [default=-mt]])

很久以前,Boost库曾经有一个-mt后缀来表示它们是多线程感知的. Debian / Ubuntu在几年前就放弃了.也许其他发行版保留了它. Boost库的名称在任何情况下都从未非常标准化,这就是配置脚本经常尝试处理它们的原因,通常是以破碎的方式处理它们.

你可以删除这两行或者像这样调用它:

$BOOST_LIB_SUFFIX="" ./autogen.sh

正确的解决方法是将脚本转换为使用the Autoconf Archive中的Boost宏.

c# – System.IO.Compression在ASP.NET VNext中完整的CLR

c# – System.IO.Compression在ASP.NET VNext中完整的CLR

我试图在VS2015 Preview中的ASP.NET VNext类库中使用System.IO.Compression.ZipArchive.我使用NuGet添加了System.IO.Compression包,并将其作为aspnetcore50依赖项添加到我的project.json中.

当我尝试使用ZipArchive时,Intellisense说在ASP.NET 5.0中不可用,但它在ASP.NET Core 5.0中可用.如果我切换到使用顶部栏中的下拉列表使用ASP.NET Core,那么我的代码按预期工作,但是当我选择正常的ASP.NET它不起作用.

我尝试手动添加它作为一个依赖项到aspnet50在project.json,但是没有修复它.

我需要在Core CLR上使用完整的CLR,因为我需要在运行时将程序集加载到AppDomain中,我相信Core CLR不支持这种方式.

请有人解释这里发生了什么,也许指出一些文章或博客文章,告诉我如何解决这个问题.

更新:
我想一个更好的方法或措辞这是 – ZipArchive在aspnet50中不可用,但是当我添加System.IO.Compression NuGet软件包时,它可以在aspnetcore50中使用.为什么是这样?

解决方法

他们只有我得到项目编译和工作正在project.json中进行以下操作.我不太熟悉压缩库,所以我没有花时间尝试压缩文件.下面你将会编写一个没有问题的代码.
{
    "version": "1.0.0-*","dependencies": {

    },"frameworks": {
        "aspnet50": {
            "dependencies": {

            },"frameworkAssemblies": {                
                "System.IO.Compression": "4.0.0.0"

            }
        },"aspnetcore50": {
            "dependencies": {
                "System.Runtime": "4.0.20-beta-22231","System.IO.Compression.ZipFile": "4.0.0-beta-22231","System.IO": "4.0.10-beta-22231","System.IO.FileSystem": "4.0.0-beta-22231"

            }
        }
    }
}

示例代码

public static void ZipFile(string path)
    {
        var data = new MemoryStream(File.ReadAllBytes(path));
        var zip = new ZipArchive(data,ZipArchiveMode.Create,false);
        zip.CreateEntry(path + ".zip");            
    }

我们今天的关于我在“ System.IO.Compression”命名空间中找不到“ ZipFile”类未找到命名空间的分享就到这里,谢谢您的阅读,如果想了解更多关于.net – My.Computer.FileSystem和System.IO.File之间究竟有什么区别、asp.net – system.web.compilation.debug与system.codedom.compilers.compiler.compilerOptions / define:Debug = True、c – configure:error:找不到boost.filesystem库、c# – System.IO.Compression在ASP.NET VNext中完整的CLR的相关信息,可以在本站进行搜索。

本文标签: