可配合 Costura.Fody 使用的 SevenZipExtractor
C# SevenZipExtractor
with Costura.Fody
A = 当前的 SevenZipExtractor 项目
B = 目标项目 将调用 SevenZipExtractor(已引用
Costura.Fody
)
在此之前 B 先 NeGet 搜索引用 Costura.Fody
,B 目录中将出现 FodyWeavers.xml
-
git clone
打开解决方案,解决方案资源管理器 选中SevenZipExtractor
右键 生成,SevenZipExtractor.dll 将会出现在A/bin/Release/
中- 跳过此步骤,可直接下载 SevenZipExtractor.dll
-
复制
A 目录/bin/Release/SevenZipExtractor.dll
到B 目录
中 -
B
中引用 SevenZipExtractor.dll 并配置复制本地=False
如图 -
B
中创建目录Costura32
和Costura64
并将A 目录/bin/Release/(x86|x64)/7z.dll
对应放入其中,对 .dll 文件进行配置生成操作=嵌入的资源, 复制到输出目录=不复制
如图所示 -
配置
FodyWeavers.xml
<Weavers> <Costura CreateTemporaryAssemblies='true' Unmanaged32Assemblies='7z|SevenZipExtractor' Unmanaged64Assemblies='7z|SevenZipExtractor' IncludeAssemblies='SevenZipExtractor'/> </Weavers>
-
好啦好啦 清理 再 生成 B 即可。现在就只有一个文件了,
7z.dll
和SevenZipExtractor.dll
都已嵌入单个.exe
中
C# wrapper for 7z.dll (x86 and x64 included)
Based on code from: http://www.codeproject.com/Articles/27148/C-NET-Interface-for-Zip-Archive-DLLs
Supported formats:
- 7Zip
- APM
- Arj
- BZip2
- Cab
- Chm
- Compound
- Cpio
- CramFS
- Deb
- Dll
- Dmg
- Exe
- Fat
- Flv
- GZip
- Hfs
- Iso
- Lzh
- Lzma
- Lzma86
- Mach-O
- Mbr
- Mub
- Nsis
- Ntfs
- Ppmd
- Rar
- Rar5
- Rpm
- Split
- SquashFS
- Swf
- Swfc
- Tar
- TE
- Udf
- UEFIc
- UEFIs
- Vhd
- Wim
- Xar
- XZ
- Z
- Zip
Install-Package SevenZipExtractor
using (ArchiveFile archiveFile = new ArchiveFile(@"Archive.ARJ"))
{
archiveFile.Extract("Output"); // extract all
}
using (ArchiveFile archiveFile = new ArchiveFile(@"Archive.ARJ"))
{
foreach (Entry entry in archiveFile.Entries)
{
Console.WriteLine(entry.FileName);
// extract to file
entry.Extract(entry.FileName);
// extract to stream
MemoryStream memoryStream = new MemoryStream();
entry.Extract(memoryStream);
}
}
7z.dll (x86 and x64) will be added to your BIN folder automatically.
- Source code in this repo is licensed under The MIT License
- 7z binaries license http://www.7-zip.org/license.txt