1

I have a .NETCore app which I am trying to add 7 zip functionality to.

Compiling gives this warning: warning NU1701: Package 'SevenZipSharp 0.64.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net5.0'. This package may not be fully compatible with your project.

So I presume the project is .NETCore v5.0. Can I run SevenZipSharp in this project?

Running the app gives an error at the call to CompressFiles: SevenZip.SevenZipLibraryException: 'Can not load 7-zip library or internal COM error! Message: failed to load library.'

public void ZipQOB(string sevenZipDllPath, string zippedQobPath, string unzippedQobFiles)//List<string> sourceFiles)
    {
        // throw exception if paths passed in are null, does 7zipsharp throw exceptions in this case?
        try
        {
            if (System.IO.File.Exists(sevenZipDllPath) && System.IO.Directory.Exists(zippedQobPath))// && System.IO.Directory.Exists(unzippedQOBFiles))
            {
                string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "7z.dll");
                //SevenZipCompressor.SetLibraryPath(sevenZipDllPath);
                SevenZipCompressor.SetLibraryPath(path);
                SevenZipCompressor sevenZipCompressor = new()
                {
                    CompressionLevel = SevenZip.CompressionLevel.Ultra,
                    CompressionMethod = CompressionMethod.Lzma
                };

                string[] files = System.IO.Directory.GetFiles(unzippedQobFiles);
                sevenZipCompressor.CompressFiles(zippedQobPath + @"\zip.QOB", files);
                //System.IO.Path.ChangeExtension(zippedQobPath, ".QOB");
            }

This question How do I use 7zip in a .NET Core app running on Linux? mentions a CLI wrapper ported from .NET Framework to .NET Core, but I can't find any details - is this something I would have to write and how?

I have already tried things suggested elsewhere, I altered the project build setting to: Platform Target = AnyCPU, ticked Prefer 32-bit

Should I just look at a different option as this page seems lists some stating .netcore compatible: https://github.com/topics/7zip?l=c%23

Many thanks for any help :)

user686027
  • 85
  • 4
  • Is there any reason you don't just use `ZipArchive` from the standard .NET library – Charlieface Sep 13 '22 at 10:32
  • Hi, thanks for the suggestion. Our files have previously been zipped using 7-zip so it is important to keep the method the same to prevent compatibility issues. Does the .NET ZipArchive do 7-zip? – user686027 Sep 13 '22 at 15:03
  • Maybe use SharpZipLib, see https://stackoverflow.com/questions/222030/how-do-i-create-7-zip-archives-with-net – Charlieface Sep 13 '22 at 15:13
  • Thanks for the suggestion, but it says that SharpZipLib doesn't do 7 zip. The only one in the list which looks like it might work is the LZMA sdk – user686027 Sep 15 '22 at 14:40

0 Answers0