A very important experience: how to make the compatible code for every .NET in one copy and deploy one copy installation to each .NET framework?
Posted by Admin L in .NET Programming on 18-08-2011. Tags: .NET Programming Experience
Author: Nosa Lee
Original Address: https://www.seeksunslowly.com/do-not-application-compatible-deployment
To reprint this article, please indicate the source, thank you.
_____________________________________
You’ll want to more people to use your software with worked hard! But .NET framework has several versions, such as 1.0, 1.1, 2.0, 3.0, 3.5 and 4.0, how to let one copy of your code and installation to be compatible in so many .NET framework versions and delopy to them? Through research and practice, I summed up the following solution, hope it is helpful.
First, decide the minimum. NET version that you want to support in your application (I use .NET 2.0), and then just do the following things:
1. Change application target .NET framework version to 2.0, location: Project Property -> Compile -> Advanced Compile Options…
Note: This is only for code level compatibility, you may write the code that cannot be supported by the low version .NET frameworks without this target .NET framework version setting. I think you know:)
2. Modify app.config file (if not exist, just create one), add or change the following code between <configuration></configuration>:
[cc lang=”xml”]
[/cc]
As above, <supportedRuntime/> are used to list the target CLR versions that you want to support in your application, there are 4 CLRs currently (as of today, Aug 18, 2011):
** .NET 1.0 and 1.1 has a different CLR version each, now I do not want to support, so not given.
** The CLR versions of .NET 2.0, 3.0 and 3.5 are same: v2.0.50727.
** .NET 4.0 (latest version)’s CLR version is v4.0.x, and from .NET 4.0, you only need to write the main and minor versions in “supportedRuntime”, so write it as “v4.0” as well (Microsoft recommends).
Now compile your application, the executable file under bin\release can run in the .NET framework 2.0, 3.0, 3.5 and 4.0 (even if only installed one version of .NET frameworks) properly.
Deployment: just copy or install the files under bin\release and other files that your application needs to target PCs.
Note: The compiler will make a “executable file name.config” file according to the second configuration, you must publish this file, otherwise, everything is wasted.