-3

I'm working on an old project. It was built by others long time ago, and it was built on .Net 2.0. Now, I need to add a new feature to it. However, coding wise, the new feature is supported by API/Class based on .Net 4.0. Obviously, it has to reference some new dll based on .Net 4. So, I made 2 versions of the program. One is for .Net 2.0 which does not have the new feature, and the other is .Net 4.0.

Now, the project manager asked: is it possible to make these 2 versions into ONE version? so in the code, it detects the .Net version, and then decides whether enable/disable the new feature.

If the user had .Net 4.0 installed, this should not be a problem. HOWEVER, there are some users, they are still using old windows servers which only have .Net 2.0 installed, and because of their work, install .Net 4.0 and reboot the system will be a problem. So, basically, this means the program has to be able to run on .Net 2.0.

Is this possible? How to do it? Any suggestions?

Thanks

****** add more info

I can detect .Net version. but I want to know how to do this:

If on the user's system, it is .net 2.0, run the code supported by .net 2.0 only; if the user's system is .net 4.0, run the code supported by .net 4.0.

Thanks

urlreader
  • 6,319
  • 7
  • 57
  • 91

1 Answers1

4

You need to target a .NET framework when doing a build. You're going to need to create 2 separate builds.

Darren Gourley
  • 1,798
  • 11
  • 11
  • 1
    Yes. it will work as you suggested. However, my question is: is there a way to do this using ONE build? Thanks. – urlreader Nov 12 '15 at 22:51
  • 1
    @urlreader No, there is no was you can do this with ONE build. You could maybe use conditional compilation blocks for your own defined definitions. This might enable you to have the same codebase, however you would still need to do two builds. Check out this answer http://stackoverflow.com/questions/2923210/conditional-compilation-and-framework-targets Let me know how it works out for you. – Darren Gourley Nov 12 '15 at 23:02