1

I'm working on a mixed mode exe that performs 7z extraction. I'm using SevenZipExtractor and need to specify the 7z lib path, so I added the 7z.Libs package which has both 32/64bit dlls and I want to embed them in my exe.

How do I make the build embed the same name dlls with different name? /bin/x86/7zxa.dll -> 7zxa_x86.dll /bin/x64/7zxa.dll -> 7zxa_x64.dll

So I can do something like this:

SevenZipExtractor.SetLibraryPath(util.is_64bit_process ? "7zxa_x64.dll" : "7zxa_x86.dll");

I'm using Fody/Costura to load other dlls, but can't figure out if and how to use it to do what I want here.

Also I really don't want to forced to add the dlls directly (with different names) to my project code dirs (repository issues).

Edit I've added the dll's as links to the project:

<ItemGroup>
    <EmbeddedResource Include="..\packages\7z.Libs.15.12.0\bin\x86\7zxa.dll">
      <Link>7z\x86\7zxa.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </EmbeddedResource>
    <EmbeddedResource Include="..\packages\7z.Libs.15.12.0\bin\x64\7zxa.dll">
      <Link>7z\x64\7zxa.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </EmbeddedResource>
</ItemGroup>

The dll's are indeed embedded into the exe:

ystem.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames()
        [0] "xxx.g.resources"   string
        [1] "xxx.Properties.Resources.resources"    string
        [2] "xxx.version"   string
        [3] "xxx._7z.x86.7zxa.dll"  string
        [4] "xxx._7z.x64.7zxa.dll"  string
        [5] "costura.asyncbridge.net35.dll" string
        [6] "costura.hardcodet.wpf.taskbarnotification.dll" string
        [7] "costura.newtonsoft.json.dll"   string
        [8] "costura.sevenzipsharp.dll" string
        [9] "costura.system.threading.dll"  string

However I'm still not able to get the SevenZip lib to load the dll:

SevenZipExtractor.SetLibraryPath(util.is_64bit_process ? @"7z\x64\7zxa.dll" : @"7z\x86\7zxa.dll");

also tried @"_7z.x64.7zxa.dll" as appears in the Assemblies list, no luck.

Any suggestions?

Shachar
  • 359
  • 2
  • 6

1 Answers1

0

You can't add two files of the same name to the zip file if they are in the same folder - but you can add folders to the zip file.

So if you create two folders in the zip file called "x86" and "x64" (say) then you can add the dll to relevant dll and your code will become:

SevenZipExtractor.SetLibraryPath(util.is_64bit_process ? @"x64/7zxa.dll" : @"x86/7zxa.dll");
ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • I'm quite new to c#, can you please elaborate or link me to how do I create these folders with the dlls in my build (and how to embed them)? – Shachar Jan 13 '16 at 11:35
  • @Shachar I'm not sure I understand you question. Are you building the 7zxa.dll or is it a dependency of your project? If it's the former then the folders should be created automatically if you've set your project up correctly. If it's the latter then you can create the folders manually. – ChrisF Jan 13 '16 at 11:38
  • I think I might not explained myself correctly, I'm creating an application that part of what it can do is extract 7z archives, I need to embed the two 7zxa.dll versions (from an external source) inside the exe and allow the code to decide at runtime which version of the dll to run. – Shachar Jan 13 '16 at 12:07