-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

4
  • So you want to know if you can detect the version of .net? The answer to that question is yes. Commented Nov 12, 2015 at 22:35
  • not really. I added more info for the question. thanks. Commented Nov 12, 2015 at 22:40
  • take a look here and see if this helps stackoverflow.com/questions/13461185/… Commented Nov 12, 2015 at 22:42
  • if (.net == 2.0) { run 2.0 } else if (.net == 4.0) { run 4.0 }. But really, this is far too broad. Commented Nov 12, 2015 at 22:42

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

Yes. it will work as you suggested. However, my question is: is there a way to do this using ONE build? Thanks.
@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 stackoverflow.com/questions/2923210/… Let me know how it works out for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.