C#/.NET: Creating a CAB and adding files to it without an external library

丶灬走出姿态 提交于 2020-01-03 19:02:17

问题


I'm aware there is a similar question but the marked answer provides a link to an external library which requires several dependencies to be installed on the user's machine.

I don't need extraction or anything else fancy like listing files - I only need to add the entire contents of a folder to a single cabinet file. I know cabinet.dll exists in the \Windows\System32 folder and I'm hoping there's a simple way to interact with this DLL to achieve what I'm trying to do.

Is it possible to do this without an external library? If anyone could point me in the right direction I'd be eternally grateful.


回答1:


You may take a look at WiX and more specifically the Microsoft.Deployment.Compression.Cab assembly. It has a nice API that allows you to do this:

CabInfo cab = new CabInfo(@"c:\Work\some.cab"); 
cab.Pack(@"C:\Work\folder");

It's dependent on the Microsoft.Deployment.Compression assembly which is standalone so you will need only those two assemblies.



来源:https://stackoverflow.com/questions/1939639/c-net-creating-a-cab-and-adding-files-to-it-without-an-external-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!