使用已在 PC 上的 Oracle.DataAccess.DLL,不提供它

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4492462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:15:06  来源:igfitidea点击:

Using Oracle.DataAccess.DLL already on PC, not providing it

c#oracledll

提问by Sean Anderson

I am looking to make my program more dynamic. I would like it to be able to support an Oracle 10g and an Oracle 11g database with the same program. If I build the program using the .DLL reference for one version then the other fails. Is there a way to use the Oracle.DataAccess.DLL that is already on the computer being installed upon, instead of providing the DLL in my installer?

我希望让我的程序更具活力。我希望它能够使用相同的程序支持 Oracle 10g 和 Oracle 11g 数据库。如果我使用一个版本的 .DLL 引用来构建程序,那么另一个版本就会失败。有没有办法使用已安装在计算机上的 Oracle.DataAccess.DLL,而不是在我的安装程序中提供 DLL?

Thanks in advance.

提前致谢。

回答by Matthew Rodatus

SpecificVersion is an attribute that applies only during build time. It was designed to assist if there are multiple versions of an assembly in the build environment; when SpecificVersion is true, it will ensure that you build against and reference the desired version. Once the target assembly is built, however, its references contain the strong name and the version number of the referenced assembly. So, if SpecificVersion is false, it's going to be set to reference whatever was the available version of the reference in the build environment at the time.

SpecificVersion 是一个仅在构建时适用的属性。它旨在帮助构建环境中有多个版本的程序集;当SpecificVersion 为true 时,它​​将确保您构建并引用所需的版本。但是,一旦构建了目标程序集,它的引用就包含强名称和被引用程序集的版本号。因此,如果 SpecificVersion 为 false,它将被设置为引用当时构建环境中引用的任何可用版本。

"Note that the Specific Version property is only a build-time directive, and it has no effect on the runtime version resolution of the referenced assembly" (http://www.code-magazine.com/article.aspx?quickid=0507041&page=3).

“请注意,Specific Version 属性只是一个构建时指令,它对引用程序集的运行时版本解析没有影响”(http://www.code-magazine.com/article.aspx?quickid=0507041&page =3)。

However, you could use version redirection to explicitly annotate that you accept any version. The oldVersion field specifies anything (the version you built against), and the newVersion attribute would specify which one you want to actually link against at runtime.

但是,您可以使用版本重定向来明确注释您接受任何版本。oldVersion 字段指定任何内容(您构建的版本),而 newVersion 属性将指定您希望在运行时实际链接的版本。

  <dependentAssembly>
    <assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89B483F429C47342"/>
    <bindingRedirect oldVersion="1.0.0.0-2.111.9999.9999" newVersion="2.102.2.20"/>
  </dependentAssembly>

(See http://msdn.microsoft.com/en-us/library/7wd6ex19.aspx.)

(请参阅http://msdn.microsoft.com/en-us/library/7wd6ex19.aspx。)

That dependentAssembly node can be applied to different contexts. One possible context would be in a web.config or app.config as a child of the configuration/runtime/assemblyBinding node.

该dependentAssembly 节点可以应用于不同的上下文。一种可能的上下文是在 web.config 或 app.config 中,作为 configuration/runtime/assemblyBinding 节点的子节点。

To answer your particular scenario of supporting both Oracle 10g and 11g? There are two options, the former of which was suggested by the user @BQ:

回答您支持 Oracle 10g 和 11g 的特定场景?有两个选项,前者是用户@BQ 建议的:

  1. Deploy only one version of ODP.NET. You should be able to talk to both versions of the database server (10g and 11g) from either version of ODP.NET (10g or 11g). See @BQ's answer below.
  2. If you really need to be able to link to two different assembly versions, you will need to have two different version redirection configurations. In other words, you'd need two app.config files, one of which contains a version redirection to the 10g ODP.NET version and the other to the 11g ODP.NET version.
  1. 仅部署一个版本的 ODP.NET。您应该能够从 ODP.NET 的任一版本(10g 或 11g)与两个版本的数据库服务器(10g 和 11g)进行通信。请参阅下面的@BQ 的回答。
  2. 如果你真的需要能够链接到两个不同的程序集版本,你将需要有两个不同的版本重定向配置。换句话说,您需要两个 app.config 文件,其中一个包含指向 10g ODP.NET 版本的版本重定向,另一个包含指向 11g ODP.NET 版本的版本重定向。

A few more tips:

还有一些提示:

  1. Make sure you remove any Oracle-provided publisher policies from the GAC. These take precedence over ones in web/app.config
  2. By default, binding failures are cached, so if the ODP.NET assembly happened to fail binding with the version redirection, you'll need to restart IIS to purge the cached failures.
  1. 确保从 GAC 中删除所有 Oracle 提供的发布者策略。这些优先于 web/app.config 中的
  2. 默认情况下,绑定失败会被缓存,因此如果 ODP.NET 程序集碰巧与版本重定向绑定失败,则需要重新启动 IIS 以清除缓存的失败。

回答by CodingGorilla

If you select the reference in Visual Studio and go to the Properties window (F4 by default), you'll see an option labeled "Specific Version". If you set this to false, the project will accept different versions of the DLL.

如果您在 Visual Studio 中选择引用并转到“属性”窗口(默认为 F4),您将看到一个标记为“特定版本”的选项。如果将此设置为 false,项目将接受不同版本的 DLL。

Now this doesn't necessarily mean that the project will findthe version of the DLL. If it isn't near the .exe (i.e. in the folder, or subfolder) or in the GAC, then you'll have to do some work on your own to load it.

现在这并不一定意味着项目会找到DLL 的版本。如果它不在 .exe 附近(即在文件夹或子文件夹中)或在 GAC 中,那么您必须自己做一些工作来加载它。

回答by BQ.

See @MattRodatus' excellent answer about using a binding redirect if you need to get your application to support multiple versions of Oracle.DataAccessthat might be on a machine you're deploying to.

如果您需要让您的应用程序支持Oracle.DataAccess可能在您部署到的机器上的多个版本,请参阅@MattRodatus 关于使用绑定重定向的出色回答。

However, you should be able to access a 10g or an 11g database with either version of the Oracle client installation.

但是,您应该能够使用任一版本的 Oracle 客户端安装访问 10g 或 11g 数据库。

See the @the.jxc's answer at Oracle: Does a 10g oracle client work with an 11g server?for a good synopsis of which clients support which databases.

请参阅Oracle 上的@the.jxc 的回答:Does a 10g oracle client work with an 11g server? 获取有关哪些客户端支持哪些数据库的完整概要。