Oracle.Dataaccess 在 GAC 中。我可以控制我使用的版本吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9374323/
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-19 00:37:48  来源:igfitidea点击:

Oracle.Dataaccess is in the GAC. Can I control the version I use?

.netoracleodp.net

提问by Arve

I have a XCOPY deployable .NET application using Oracle.DataAccess (ODP.NET). We also deploy the Oracle Instant client in the application directory. Everything works OK, but I worry..

我有一个使用 Oracle.DataAccess (ODP.NET) 的 XCOPY 可部署 .NET 应用程序。我们还在应用程序目录中部署了 Oracle Instant 客户端。一切正常,但我担心..

From the Oracle ODP.NET FAQ:

来自 Oracle ODP.NET 常见问题解答:

Beginning with ODP.NET 10.1.0.3, the Oracle installer will register the following publisher policy DLLs in the Global Assembly Cache (GAC) that redirect 9.2, 10.1 and 10.2 ODP.NET applications to use the last installed version of ODP.NET: Policy.9.2.Oracle.DataAccess.dll and Policy.10.1.Oracle.DataAccess.dll

从 ODP.NET 10.1.0.3 开始,Oracle 安装程序将在全局程序集缓存 (GAC) 中注册以下发布者策略 DLL,这些 DLL 将 9.2、10.1 和 10.2 ODP.NET 应用程序重定向到使用最后安装的 ODP.NET 版本:策略.9.2.Oracle.DataAccess.dll 和 Policy.10.1.Oracle.DataAccess.dll

This means that on machines where the Oracle ODP.NET is installed, the version in the GAC will be used, not the one I deploy with my application. And because of the publisher policy, that version may be newer than the one I deploy with my application. Oracle.DataAccess needs the Oracle (Instant) client also deployed with my application. These are native Win32 DLLs so my version will be used.

这意味着在安装了 Oracle ODP.NET 的机器上,将使用 GAC 中的版本,而不是我与应用程序一起部署的版本。而且由于发布者政策,该版本可能比我用我的应用程序部署的版本更新。Oracle.DataAccess 需要与我的应用程序一起部署的 Oracle(即时)客户端。这些是本机 Win32 DLL,因此将使用我的版本。

Is is possible that Oracle may upgrade the Oracle.DataAccess to a newer version that may not be compatible with the Oracle Instant Client deployed with my application? And thus breaking my application in the future.

Oracle 是否可能将 Oracle.DataAccess 升级到可能与我的应用程序部署的 Oracle Instant Client 不兼容的较新版本?从而在未来打破我的应用程序。

Is this a problem? And can I avoid it? Without installing/removing anything on the machine can I override the Oracle Publishers policy to guarantee that I user the Oracle.Dataaccess version that I xcopy deploy with my application?

这是一个问题吗?我可以避免吗?在机器上不安装/删除任何东西的情况下,我是否可以覆盖 Oracle Publishers 策略以保证我使用 xcopy 随我的应用程序部署的 Oracle.Dataaccess 版本?

For a given version of ODP.NET, what Oracle Clients versions does it support? Will new versions of Oracle.DataAccess support old versions of the Oracle (Instant) Client.

对于给定版本的 ODP.NET,它支持哪些 Oracle 客户端版本?新版本的 Oracle.DataAccess 是否支持旧版本的 Oracle(即时)客户端。

回答by Martin Suchanek

It's possible to force your application to always use the ODP and ODAC version you want.

可以强制您的应用程序始终使用您想要的 ODP 和 ODAC 版本。

  1. Force ODP version: use the assemblyBinding trick posted by Robert, to force using your version of Oracle.DataAccess instead of the GAC'd version. E.g.:

    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Oracle.DataAccess"  culture="neutral" publicKeyToken="89b483f429c47342"/>
            <codeBase version="4.112.3.0" href="FILE://Oracle.DataAccess.dll"/>
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>
    
  2. Force ODAC version: The ODP DLL depends on a set of shared Oracle components (instant client, unmanaged OCI dlls). One way to get these is via the ODAC package. You can define (on a per app basis), which ODAC package you want to use. Traditionally this was done via the PATH env variable, but it can now be defined via config:

    <configuration>
      <configSections>
        <section name="oracle.dataaccess.client" type="System.Data.Common.DbProviderConfigurationHandler, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </configSections>
    
      <oracle.dataaccess.client>
        <settings>
          <add name="DllPath" value="C:\somefolder\ODAC_11.2.0.3.0_32bit\bin" />
        </settings>
      </oracle.dataaccess.client>
    </configuration>
    
  3. As an extra precaution, you can always delete the GAC'd publisher policy DLL, to ensure there is never any funky going on.

  1. 强制 ODP 版本:使用 Robert 发布的 assemblyBinding 技巧,强制使用您的 Oracle.DataAccess 版本而不是 GAC 版本。例如:

    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Oracle.DataAccess"  culture="neutral" publicKeyToken="89b483f429c47342"/>
            <codeBase version="4.112.3.0" href="FILE://Oracle.DataAccess.dll"/>
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>
    
  2. 强制 ODAC 版本:ODP DLL 依赖于一组共享的 Oracle 组件(即时客户端、非托管 OCI dll)。获得这些的一种方法是通过 ODAC 包。您可以(基于每个应用程序)定义要使用的 ODAC 包。传统上这是通过 PATH 环境变量完成的,但现在可以通过配置来定义:

    <configuration>
      <configSections>
        <section name="oracle.dataaccess.client" type="System.Data.Common.DbProviderConfigurationHandler, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </configSections>
    
      <oracle.dataaccess.client>
        <settings>
          <add name="DllPath" value="C:\somefolder\ODAC_11.2.0.3.0_32bit\bin" />
        </settings>
      </oracle.dataaccess.client>
    </configuration>
    
  3. 作为额外的预防措施,您可以随时删除 GAC 的发布者政策 DLL,以确保不会发生任何奇怪的事情。

回答by YudhiWidyatama

I combined Robert & Arve's answer with my previous efforts :

我将 Robert & Arve 的回答与我之前的努力结合起来:

  • Set SpecificVersion to True in the Project's Oracle.DataAccess properties, and make sure the Version stated matches with the version you want to use. If not, manually edit the csproj file to change the version number and delete the copied dll in the bin folder. Visual Studio would automatically find the version number in the GAC. If the version is not yet exist in the GAC, you should install ODAC first.

    <Reference Include="Oracle.DataAccess, Version=2.111.7.20, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86" />

  • Make sure the first OraOps11w.dll found in the Path is the version you want to use. If not, change Windows' System Path so that the directory of the Oracle Client you want to use is the first path entry.

  • 在项目的 Oracle.DataAccess 属性中将 SpecificVersion 设置为 True,并确保声明的版本与您要使用的版本匹配。如果没有,手动编辑csproj文件修改版本号,删除bin文件夹中复制的dll。Visual Studio 会自动在 GAC 中查找版本号。如果 GAC 中尚不存在该版本,则应先安装 ODAC。

    <Reference Include="Oracle.DataAccess, Version=2.111.7.20, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86" />

  • 确保在路径中找到的第一个 OraOps11w.dll 是您要使用的版本。如果不是,请更改 Windows 的系统路径,以便您要使用的 Oracle 客户端的目录是第一个路径条目。

C:\app\user\product\11.1.0\client_1;C:\app\user\product\11.1.0\client_1\bin;other path

C:\app\user\product\11.1.0\client_1;C:\app\user\product\11.1.0\client_1\bin; 其他路径

  • Disable publisher policy apply in the Web.config or App.config file
  • 在 Web.config 或 App.config 文件中禁用发布者策略应用
  <configuration>
...
     <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
...
            <dependentAssembly>
            <assemblyIdentity name="Oracle.DataAccess"
                                    publicKeyToken="89b483f429c47342"
                                    culture="neutral" />
            <publisherPolicy apply="no"/>
            </dependentAssembly>
        </assemblyBinding>
     </runtime>
  </configuration>

It might be better to close Visual Studio while editing csproj / web.config files in Notepad++ or your favorite text editor. But usually Visual Studio asks you whether you want to reload the project or not.

在 Notepad++ 或您喜欢的文本编辑器中编辑 csproj / web.config 文件时,最好关闭 Visual Studio。但通常 Visual Studio 会询问您是否要重新加载项目。

回答by Robert

You can use assemblyBinding in the app.config file.

您可以在 app.config 文件中使用 assemblyBinding。

Heres a couple of links that show how to use it.

这里有几个显示如何使用它的链接。

http://blogs.msdn.com/b/suzcook/archive/2004/05/14/132022.aspxhttp://stackoverflow.com/questions/1165190/is-there-a-way-to-force-using-a-dll-version

http://blogs.msdn.com/b/suzcook/archive/2004/05/14/132022.aspxhttp://stackoverflow.com/questions/1165190/is-there-a-way-to-force-using -a-dll-版本

回答by Stuart Smith

To get Oracle 11 and 12 to play nicely together I had to make the following changes to my app.config file. This is the only change I made, I did not make any changes to my project file such as changing the specific version from false to true.

为了让 Oracle 11 和 12 很好地协同工作,我必须对我的 app.config 文件进行以下更改。这是我所做的唯一更改,我没有对我的项目文件进行任何更改,例如将特定版本从 false 更改为 true。

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>

  <!--Add This Section to run Oracle 11 and !2 side By Side  -->
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Oracle.DataAccess"  culture="neutral" publicKeyToken="89b483f429c47342"/>
        <codeBase version="4.112.4.0" href="FILE://Oracle.DataAccess.dll"/>
        <publisherPolicy apply="no"/>
      </dependentAssembly>
    </assemblyBinding>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Oracle.DataAccess"  culture="neutral" publicKeyToken="89b483f429c47342"/>
        <codeBase version="4.112.3.0" href="FILE://Oracle.DataAccess.dll"/>
        <publisherPolicy apply="no"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <!--Add the above Section to run Oracle 11 and 12 side By Side  -->