For some reason I’ve always had trouble remembering the backwards/forwards compatibility guarantees made by the framework, so I’d like to put that to bed forever.
Suppose I have two assemblies, A and B. A is older and references .NET 2.0 assemblies; B references .NET 3.5 assemblies. I have the source for A and B, Ax and Bx, respectively; they are written in C# at the 2.0 and 3.0 language levels. (That is, Ax uses no features that were introduced later than C# 2.0; likewise Bx uses no features that were introduced later than 3.0.)
I have two environments, C and D. C has the .NET 2.0 framework installed; D has the .NET 3.5 framework installed.
Now, which of the following can/can’t I do?
Running:
- run
AonC? runAonD? - run
BonC? runConD?
Compiling:
- compile
AxonC? compileAxonD? - compile
BxonC? compileBxonD?
Rewriting:
- rewrite
Axto use features from the C# 3 language level, and compile it onD, while having it still work onC? - rewrite
Bxto use features from the C# 4 language level on another environmentEthat has .NET 4, while having it still work onD?’
Referencing from another assembly:
- reference
BfromAand have a client app onCuse it? - reference
BfromAand have a client app onDuse it? - reference
AfromBand have a client app onCuse it? - reference
AfromBand have a client app onDuse it?
More importantly, what rules govern the truth or falsity of these hypothetical scenarios?
No problem here.
You can’t run
BonCbecause it references 3.5 assemblies which are not available onC. No problem to runConD.No problem here.
You can’t compile
BxonCbecause it doesn’t have the 3.5 assemblies installed which it references. No problem to compileBxonD.Yes this is possible.
No this is not possible because if you target the CLR 4.0 the assembly won’t be able to run on a previous CLR version.
As a conclusion:
ildasm.exe yourassembly.dll. Double click onMANIFEST, look atMetadata version. If it isv2.0.50727it means that this assembly has been compiled for the CLR 2 version. Then you look at the referenced assemblies. If in the references you see a referenced assembly calledSystem.***with version 3.5.0.0 it means that .NET 3.5 framework is required. If not it probably will run fine with only .NET 2.0 installed (of course it shouldn’t reference any other assembly that itself depends on .NET 3.5).