Sfx target .NET2.0

Apr 20, 2011 at 4:02 PM

I have a desktop application that requires .NET4.0 to operate.  As one of it's operations, it's creates some self-extracting zips.  These still target .NET4.0, but I need them to target .NET2.0.  Is that possible, or will the Sfx's always inherit the framework of the parent application?  The PC's they are running on are guaranteed to have .NET2.0 but not guaranteed to have .NET4.0, so that's why I'd like for them to target that older framework.

Apr 20, 2011 at 5:56 PM

Good question.

It was my intention that the machine that runs a DotNetZip-generated SFX would required .NET 2.0, only.  But, I don't have a .NET 4.0 machine, and I have not tested the case you described. I would guess it would "just work" but I'm not sure.

I cannot remember now, what I specified for the compiler switches that DotNetZip uses when generating the SFX.  

The way it works is that, within ZipFile.SaveSelfExtractor(),  DotNetZip calls into the CSharpCompiler classes, which actually causes csc.exe to be invoked. And there is an option to csc.exe that allows you to specify the target framework.  I'm pretty sure (not looking at the code right now) that I used that switch to insure the .NET 2.0 dependency.  I would expect that this compiler switch also exists on the .NET Framework 4.0 version of the compiler.

I'll have to look at the code.  In the meantime, I don't have a .NET 4.0 machine; would it be possible for you to generate an SFX on your .NET 4.0 machine and then try running it on a machine with only .NET 2.0?


Apr 20, 2011 at 7:32 PM

Cheeso - that is what I have done, and I get an error that the workstation needs to have .NET Framework version 4.0.xxxxx installed for it to extract.  Tonight I am going to try to recompile my app as .NET 2.0 and see if that makes any difference.  The other option is csc.exe is different on my machine because I'm running Win7.

I'm looking ZipFile.SaveSelfExtractor.cs and I don't see any switch to csc.exe that would specify the framework.  I'm not sure what that switch is.  I don't have time to research right now but I'll take a look today/tomorrow and see.

I'm still looking at ways to minimize the Sfx file size too ... not found a good solution yet ...

Apr 20, 2011 at 8:16 PM

Well, my app won't recompile as .NET 2.0 due to an SSH plugin I'm using that requires 4.0 (SSH.NET).  Still looking into other parts ...

Apr 26, 2011 at 8:35 PM

ok let me look into this further. 

Apr 27, 2011 at 7:59 PM
Edited Apr 27, 2011 at 8:00 PM

Cheeso - I can confirm that, with my app that targets 4.0, the Sfx's require 4.0 - on a workstation with only 2.0 installed, it failed stating that 4.0 was needed.

I thought I had found the option needed, and I tested it a few moments ago but it still compiled the Sfx as 4.0.  I'm looking into it still myself.  What I did was replace your call to the CSharpCodeProvider in ZipFile.SaveSelfExtractor.cs on line 704 with:


                // target the 2.0 framework
                var compilerOptions = new Dictionary<string, string>
                    { "CompilerVersion", "v2.0" }

                Microsoft.CSharp.CSharpCodeProvider csharp = new Microsoft.CSharp.CSharpCodeProvider(compilerOptions);


According to these two articles, that should have worked, but didn't:



I'm not sure if I missed something else in the code that is overriding that setting (such as a config file) but I didn't think so.  A little stumped as to why that didn't work!

May 5, 2011 at 4:53 PM

Cheeso - well, I have no idea what I did wrong the first time, but my code snippet above works.  By adding just that line, it compiles targeting the 2.0 framework.  I think I may also add a new option to the SfxOptions to select a version.  I don't have access to commit any code, though - could I email you the finished file or could I be made a contributor?

... Feel a little dumb I failed to properly test the file that I generated the first time!  I must have copied the wrong executable over to my 2.0-only workstation to test.  Argh, it's always the little things.

May 7, 2011 at 1:30 PM

Thanks - that would be very useful.

To submit an update, you can upload a patch.  Just include the files you've modified, I'll be able to see the diff.

Thanks very much for the effort.