Search code examples
c#.netwindows-8windows-7nsis

A C# compiled via two different .NET versions in a single NSIS setup


I want to install my C# project (WinForm .NET v2) on windows 7,8,8.1 without the need of installing the .NET .

As i figured out, Windows 7 has .NET v2 by default and Windows 8,8.1 has .NET v4 by default.

So I was thinking of copying my C# project and have them compiled with both .NET v2 and v4. After that, I would make an NSIS setup with both of them using a script that could tell me which version of .NET is installed on destination system. Then just install the specific compiled project without the need of installing any .NET

The idea is theoretically OK but the problem is:

I found "no one" using this solution for their projects. What is wrong with it? Do i miss something?


Solution

  • The reason that no one1 does this (packaging .NET 2 and .NET 4 versions in the same installer) is that with a small configuration tweak, the .NET 2 version of your application can be made to work on later runtimes as well. You can refer to these questions for more information on doing that:

    Just make sure to do testing on .NET 4 the same way you would if it were a separate build, since there are a number of small but non-trivial behavior changes.


    1 At least, not with applications. With developer plugins and libraries, it might make sense, although that has more to do with Visual Studio version than runtime, since .NET 2 DLLs load happily into .NET 4 applications with no configuration changes needed.