如何选择从Excel运行的.NET框架版本? [英] How to select .NET framework version running from Excel?

查看:141
本文介绍了如何选择从Excel运行的.NET框架版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在运行.NET DLL时指定Excel使用.NET Framework 2.0版,而不是将excel.exe.config文件添加到Office Binary文件夹?

How can I specify that Excel uses the .NET framework version 2.0 when running .NET dlls other than adding an excel.exe.config file to the Office Binary folder?

我们的应用程序在Excel中运行,并使用VBA调用.NET程序集中的托管代码。我相信这样做的教科书方法是将excel.exe.config添加到Office二进制目录中,其中包含:

Our application runs in Excel and uses VBA which makes calls into managed code in .NET assemblies. I believe the textbook way of doing this is to add excel.exe.config to the Office binary directory containing:

<?xml version="1.0"?>
<configuration>
  <startup>
    <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>

此选项对我们的客户端是不可接受的,首先是因为他们根本不允许我们添加文件到Office目录,即使他们没有冒险使用.NET v1.1(它是Excel的默认选择)来打破某些应用程序。

This option is not acceptable for our clients, firstly because they simply won't allow us to add files to the Office directory and even if they did we could not risk breaking some application using .NET v1.1 which is the default choice of Excel.

我们认为的解决方案将工作是将Excel.exe文件从客户端的Office目录复制到我们自己的应用程序目录中,以在其中添加配置文件并执行该文件。它工作得很好,但是我们遇到严重的安装问题,安装脚本找不到正确的Excel版本。此外,这是一个讨厌的肮脏的首先。

The solution which we thought would work was to copy the Excel.exe file to our own applications directory from the client's Office directory, to add the config file there and execute that file. It works well but we are having serious installation problems where the install script cannot find the correct version of Excel. Plus it's a nasty kludge in the first place.

任何想法都将受到欢迎。我想知道DLL中的一层非托管(非.NET)代码是否可以工作。一些关于如何做这个或更简单的选择的建议将不胜感激,因为这是不平凡的。

Any ideas would be welcome. I wonder if a layer of unmanaged (non .NET) code in a DLL might work. Some advice on how to do this or some simpler alternative would be appreciated as this is non-trivial.


.NET app.config问题


推荐答案

配置Excel选择的运行时版本的另一种方法是更改​​以下注册表项: p>

Another way to configure the runtime version selected for Excel is to change the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\Policy\AppPatch\v2.0.50727.00000\excel.exe

默认情况下,此键强制Excel使用1.1框架;删除它(或重命名它)导致Excel加载最新版本。

By default, this key forces Excel to use the 1.1 framework; removing it (or renaming it) causes Excel to load the latest version available.

如果您担心在Excel中断开.NET 1.1,那么您可能必须最终运行excel.exe的第二个重命名副本。 .NET框架只能在给定的Windows进程中加载​​一次,因此在单独的excel.exe实例中,必须选择1.1,2.0或更高版本。

If you're worried about breaking .NET 1.1 inside Excel then you may have to end up running a second renamed copy of excel.exe. The .NET framework can only be loaded once into a given Windows process, so within a single instance of excel.exe, you have to choose between 1.1, 2.0 or higher.

这篇关于如何选择从Excel运行的.NET框架版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆