gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 12:52:47 26 4
gpt4 key购买 nike

我目前正在从事 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com