HowTo: Control which version of the framework your .NET office add-ins run under

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 ?>
<
configuration>

<
startup>

<
supportedRuntime version=v1.1.4322/>

</
startup>
</
configuration>



Update:It seems the MSDN has corrected it’s XML document declaration. For those interested I think it was missing a leading ‘?’.

Comments

David Thielen
Hi;

But what if your add-in needs .NET 1.1 and then my add-in which needs .NET 2.0 is installed. I then overwrite your config file.

??? - thanks - dave
[email protected]
6/01/2005 4:38:00 PM
DevelopersDex discussion of this topic
17/01/2005 4:18:00 AM