Sunday, June 1, 2008

Supporting Multiple Versions of the Framework with one application

Supporting different versions of the .NET Framework has been a much talked about issue for me for as long as the Framework has been around. Especially beginning with the .NET 2.0 Framework, with all the code breaking changes that went along with it. Code breaking changes come in two flavors:

  1. Design-Time breaking changes: These are changes that would only effect you, if you for example have a 1.0 or 1.1 application, and you convert and try to run the application in Visual Studio 2005, with .NET 2.0. If you don't convert or re-compile your lower framework edition application, these changes are not an issue.
  2. Runtime breaking changes: These are the breaking changes that can impact your application in a big way, if you are planning to support multiple versions of the framework with one application.

So what does that mean in plain english you may ask. The idea is the following: Lets say you have an Enterprise Level Application written in .NET 1.0 or 1.1, with which you are currently supporting people running Windows 2000 and XP. Considering that Windows XP is nearing its End of Life (you can no longer buy new machines with Windows XP installed on them very soon), you are probably thinking about making your application compatible with Windows Vista right about now. Your two options are:

  1. Program and Support multiple versions of your application for different versions of .NET Framework.
  2. Have only ONE version of your application that targets all 3 versions of the above 3 Frameworks editions.

Up to a few month ago, if someone would have told me that option #2 existed I would have laughed at them, but it is TRUE! Here is how the whole thing plays out.

Do a test conversion of your application's conversion to the higher version of the framework. What this will give you is a FULL list of warnings and errors that would break your application. ALL the code breaking changes can then be fixed in the lower version of the framework! In other words by doing a Pre-Qualification test and fixing the errors in the lower version of the framework, you will prevent those errors from ever happending in the first place. Go back and fix all the warnings and errors that would otherwise break your application. Make sure to fix them in the lowest version of the framework you want to support.

Once the code breaking changes are fixed, all you have to do is to add the following to the "startup" section of your application's "config" file:

<supportedruntime version="v2.0.50727"/>

<supportedruntime version="v1.1.4322"/>

<supportedruntime version="v1.0.3705"/>

That's it! Lets say now that you run your application on a Vista Machine which doesn't have .NET 1.0 and 1.1 installed on it by default. Your application will Automatically choose the higher version of the Framework and run using that version of the Framework. Assuming that you have already taken care of all the code breaking changes, you can now support 3 different versions of the Framework at the same time with only 1 Version of your application!

If you have any comments or questions in this regard, feel free to contact me. I would love to get some feedback on this issue, or any other programming related issues you come across.

Pete Soheil
DigiOz Multimedia

No comments: