c# - 在 .Net CORE 1.0 中解压缩存档

标签 c# .net zip asp.net-core .net-core

我目前正在从事 ASP.NET Core 1.0 项目。我想同时留在 dnxcore50dnx451。现在让我想到以下问题:

如何将 zip 存档从文件系统解压缩到目录?

"System.IO.FileSystem.Primitives": "4.0.0-beta-22816",
"System.IO.FileSystem": "4.0.0-beta-22816"

"frameworks": {
    "dnx451": {
      "frameworkAssemblies": {
        "System.IO": ""
      }
    },
    "dnxcore50": {
      "dependencies": {
        "System.IO": "4.0.10-beta-*"
      }
    }
  }

通过 project.json 中的配置,我现在可以获得 GZipStream,但我不知道如何将该流存储到目录中。不幸的是,System.IO.Compression.ZipFile.ExtractToDirectory() 方法中的 ZipFile 对象在核心框架中不存在:/。

更新:

我现在以这种方式包含它并将其从整体依赖项中删除:

"frameworks": {
"dnx451": {
  "dependencies": {
    "System.IO.Compression.ZipFile": "4.0.1-beta-23516"
  }
},
"dnxcore50": {
  "dependencies": {
    "System.IO.Compression.ZipFile": "4.0.1-beta-23516"
  }
}

当我使用核心运行应用程序时,它按预期工作,但是使用 .net Framework 4.6 运行它时,我在运行时崩溃并出现以下异常:

处理请求时发生了 n 个未处理的异常。

An unhandled exception occurred while processing the request.
FileNotFoundException: Could not load file or assembly 'System.IO.Compression.ZipFile, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.

最佳答案

您在 project.json 中需要的依赖项如下。

"frameworks": {
    "net451": {
      "frameworkAssemblies": {
        "System.IO.Compression": "4.0.0.0",
        "System.IO.Compression.FileSystem":  "4.0.0.0"
      }
    },
    "dnxcore50": {
      "dependencies": {
        "System.IO.Compression.ZipFile": "4.0.1-beta-23516"
      }
    }
  },

project.json 根目录中的依赖项适用于适用于您正在使用的所有运行时的任何包。

.net 运行时中的 frameworkAssemblies 与您在基于 csproj 的普通项目中添加的引用相同。如果您不确定要添加什么,可以在此处找到程序集。 https://msdn.microsoft.com/en-us/library/mt472912(v=vs.110).aspx .您可以在此处使用依赖项部分来获取任何特定于网络的引用。

当谈到 dnxcore50 时,依赖项引用直接来自 nuget,但您可以使用 intellisense 来找到它们。

有关 project.json 的更多信息可在此处找到 https://github.com/aspnet/Home/wiki/Project.json-file

关于c# - 在 .Net CORE 1.0 中解压缩存档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34952962/

相关文章:

c# - RegisterClientScriptInclude : What does "type" parameter do?

amazon-web-services - 在 Amazon S3 上解压缩大型 ZIP 文件

Java nio2 : map Path objects between filesystems without relying on toString

java - ZIP文件的AES加密不正确的第2个16字节 block

c#判断一个时间段内有多少小时属于特定的小时数

c# - 为什么我的列表超出了 WCF 帖子的范围?

c# - 如何在内容页可访问的 asp.net 母版页中注册程序集?

c# - 解码 8 位邮件消息 : Content-Transfer-Encoding: 8bit

c# - 比较时间时 DateTimeKind 是否被忽略?

.net - 是否可以从交易范围内的投票中排除交易?