0

I want to make single exe file that will extract a Folder with a lot of stuff inside.

I want this exe to work on computers with .net 4.0

I was trying to decompress embedded zip archive with the folder, but it is not simple with .net 4.0

jeb
  • 78,592
  • 17
  • 171
  • 225
Vadim Volodin
  • 377
  • 1
  • 2
  • 14
  • If you by saying _"it is not simple with .net 4.0"_ are referring to that you cannot use the `ZipFile` class, I have something good to tell you: The `ZipFile` class is actually usable in .NET 4.0! You just have to import the `System.IO.Compression.FileSystem.dll` file, which is located somewhere in `%SystemRoot%\Microsoft.NET\assembly\GAC_MSIL`. Try searching for it there, and when found just import it as a reference to your project and it'll work! – Visual Vincent May 05 '16 at 19:53
  • @Visual Vincent, The primary reference "System.IO.Compression.FileSystem" could not be resolved because it has an indirect dependency on the framework assembly "System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "System.IO.Compression.FileSystem" or retarget your application to a framework version which contains "System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089". – Vadim Volodin May 09 '16 at 09:39
  • It works for me? I imported it from `%SystemRoot%\Microsoft.NET\assembly\GAC_MSIL\System.IO.Compression.FileSystem\v4.0_4.0.0.0__b77a5c561934e089\System.IO.Compression.FileSystem.dll`. – Visual Vincent May 09 '16 at 12:32
  • @VisualVincent, yes, i imported this file as a reference(right click on references->add reference->browse->choose). wtf, isn't 4.0 equal with 4.0.0.0? – Vadim Volodin May 09 '16 at 12:48
  • Yes it is. But according to the error it sounds like the already existing `System.IO.Compression` namespace is the incorrect version... Are you sure you haven't accidentelly imported/referenced another version of it? – Visual Vincent May 09 '16 at 13:26
  • @VisualVincent, I am using using System.IO; using System.IO.Compression; and referencing Analyzer, Systems and System.IO.Compression.FileSystem Also, it is not an error, it is a warning(in error list window). But there is an error "The name 'ZipFile' does not exist in the current context" (in output window) – Vadim Volodin May 09 '16 at 19:21
  • Check your project's references to see if there's an invalid `System.IO.Compression` there. – Visual Vincent May 09 '16 at 19:42
  • References are ok, it works with .net 4.5, but not with 4.0 – Vadim Volodin May 10 '16 at 06:41
  • Maybe because it was included first in .NET 4.5? The reason it would work in 4.0 is that there's no .NET 4.5 specific code in the library (which apparently is the case, it has always worked for me). – Visual Vincent May 10 '16 at 07:36

1 Answers1

1

You should be able to do this by adding a .zip file to your C# installer project and setting its Build Action to "Embedded Resource." Then, your C# installer program would extract that file from itself using Assembly.GetManifestResourceStream, writing the contents of the stream to disk.

adv12
  • 8,443
  • 2
  • 24
  • 48
  • But how can I unzip it in .net 4.0? – Vadim Volodin May 07 '16 at 06:06
  • I see from the comments on your question that the trouble you're having is finding a built-in zip/unzip library. I don't know much about that, but you could certainly use a third-party library like [SharpZipLib](https://icsharpcode.github.io/SharpZipLib/) or a command-line program like [7-Zip](http://www.7-zip.org/). (There's also a .NET wrapper for 7-Zip that allows you to link to the main DLL, but I haven't tried it.) – adv12 May 09 '16 at 13:21
  • I prefer built-in, but I accept third-party. However, I am not sure I can create the situation that a single exe could use dll somehow – Vadim Volodin May 09 '16 at 19:28
  • Yeah, a full-blown 7-Zip .exe might work best for you: make it and the 7z.dll both embedded resources, then when it's time to unpack, write both of them to disk along with the embedded .zip file, then use the .exe to unzip the .zip. Kinda ugly, but it could work. – adv12 May 09 '16 at 20:14
  • Excellent! Glad to hear it. – adv12 May 16 '16 at 13:12