3

My application is a native, non-.NET application. However, at times it may need to invoke some .NET services through COM. Sometimes it needs to load a specific version of .NET to accomplish what it needs to do. (My app uses a COM interface to System.EnterpriseServices in order to programmatically register assemblies and install them in the GAC).

Normally, I could use MyApp.exe.config (as explained here) if this information was known ahead of time and didn't change between runs.

Unfortunately, the specific version of .NET to load will not be known until runtime (and in fact, may change between runs on the same system). Therefore using MyApp.exe.config will not work.

Is there a way for a native application to supply this information to Windows programmatically before it loads .NET?

(Though my application is written in Delphi, this is more of a general Windows question and answers in any language would be welcome)

4

1 回答 1

4

您将不得不编写自己的 CLR 主机,而不是依赖于 IJW“它就可以工作”的 .NET 功能。

如果机器上安装了 .NET 4,此链接描述了如何执行此操作:Loading the Common Language Runtime into a Process。使用 .NET 4,您甚至可以在同一个进程中同时加载多个版本的 CLR(尽管有一些限制)。

附加信息:使用 CLR4 Hosting API 从本机 C++ 调用 .NET 程序集

于 2013-05-03T07:16:35.097 回答