According to this article, the version of the .NET Framework that an application runs on is determined in the following order:
- Configuration file (
.config)
- Compiled version
- Latest version installed
By default if you set the target framework in Visual Studio you have a .config file that you deploy alongside your .exe. In this .config file Visual Studio creates an element <supportedRuntime> which has two attributes: version and sku
The default element for .NET 4.5 looks like this:
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
version is the version of the supported CLR - but that's not necessarily the same as the version of the .NET Framework because all of the .NET Frameworks from 4.0 to 4.7 are using the CLR 4.0.
Only sku (stock-keeping unit) specifies the exact release of the .NET Framework that your application supports.
According to this article, the sku attribute (containing a version number) is only being recognized starting with the .NET Framework 4.0.
As a side note: .NET 3.5 has used the sku as well but only to specify that you are supporting the .NET Framework Client Profile (sku="client") which doesn't exist any longer since .NET 4.5.
So the conclusion is:
You are getting the first error message because the CLR 2.0 loader in the .NET Framework 3.5 doesn't know anything about the sku attribute. It only knows that you are requesting a .NET 4.0 CLR. (If you don't have a .config file the required version of the CLR is compiled into the manifest of your .exe, which in your case is v4.0.30319.)
Only after installing the .NET Framework 4.0 the CLR 4.0 loader now reads the sku attribute and therefore knows that you also have to install the .NET Framework 4.5. That's why you're getting this two error messages.