I noticed that the office add-in I wrote recently in .NET was running under framework 2.0. That started me thinking - how do I control which version of the framework these run under? Libraries don’t get much of a say as to which version they get loaded by, they just get the framework version that the hosting application is running in. The normal way to govern this for a .NET app would be via the application configuration file, but when the host is not a .NET application what governs which framework version it runs under? It turns out that you CAN go and create an application configuration file for a COM application that can be used to control which framework version is used. Without an application configuration file, the latest compatible runtime version installed on the computer is loaded by default. I created a new text file named “WINWORD.EXE.CONFIG” in the same directory as the winword.exe image and put the following elements in and viola - I can control which framework version word will use to load it’s add-ins. This should work for any COM exe that loads .NET code via inter-op. You can use the “requiredRuntime“ element instead of the “supportedRuntime“ element if you want to run under framework 1.0 (as described here - notice in the MSDN they get the xml document declarations wrong!).
<?xml version=“1.0“ encoding=“utf-8“ ?>
Update:It seems the MSDN has corrected it’s XML document declaration. For those interested I think it was missing a leading ‘?’.