Our application is built with VS 2008, uses Linq and has Target Framework set to .NET Framework3.5.
It works OK when only .NET 3.5 or 4 is installed on the machine.<
Another useful link is this page on MSDN. This shows all of the values required in app.config if you want to just target the client profile or if you require the full profile.
If you have an unmanaged EXE calling a .NET DLL, you need to create a foo.exe.config
file as well, containing the above <startup>...
block.
The .NET Framework version 3.0 and 3.5 use version 2.0.50727 of the CLR.
Forming the question led me to the answer. As mentioned in the Element documentation,
When multiple versions of the runtime are supported, the first element should specify the most preferred version of the runtime, and the last element should specify the least preferred version.
So the way to achieve the second option ("CLR 4 if it is installed, and CLR 2 is CLR 4 is not installed") is to reverse the order of the elements in app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
This way, .NET 4 will be loaded if it is installed, and an earlier version will be loaded if not.