What happens if I remove the auto added supportedRuntime element?

The MSDN documentation doesn’t give any good explanations of this, but I found a blog post by Scott Hanselman titled “.NET Versioning and Multi-Targeting – .NET 4.5 is an in-place upgrade to .NET 4.0” that reveals:

If you are making a client app, like WinForms, Console, WPF, etc, this is all automatic. Your app.config contains that fact that you need .NET 4.5 and you’ll even get a prompt to install it.

So the config entry is all about what happens if a user with .NET 4.0 on their machine (but not .NET 4.5) tries to run your .NET 4.5 app. Both .NET 4.0 and .NET 4.5 are built on version 4 of the CLR, so they’re theoretically compatible; same binary formats and all that. The only difference between a binary built against .NET 4.0 and one built against .NET 4.5 is the libraries they reference.

So an app compiled for .NET 4.5 could run on a computer with only .NET 4.0 installed. However, it would get a runtime exception if you tried to use any APIs that didn’t exist in 4.0.

If you have this config file entry, and a user with .NET 4.0 tries to run your app, the app will not run, and the user will be prompted to install .NET 4.5. (See screenshot in Scott’s blog post.) This is a good default for most people.

If you don’t have the config file entry, then a user with .NET 4.0 will be able to run your app, but will get a runtime exception if you try to call any methods or use any types that were added in 4.5. This will be a big pain for you as a developer and for your testers. You should only do this if you have specific requirements that your app must run on .NET 4.0 and must take advantage of new 4.5 features if they’re present (and you’ll have to be careful about exception handling and test extensively on both versions).

If you want to be able to run on .NET 4.0, but don’t need any new 4.5 APIs, then your life is much simpler: just go to the Build tab of Project Properties, and target .NET 4.0. Then the compiler will ensure that you don’t call any APIs that didn’t exist in 4.0, and your app will run successfully on both .NET 4.0 and .NET 4.5 machines.

Leave a Comment