oracle 如何不引用特定版本的程序集?

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

How not to reference a specific version of an assembly?

c#oraclevisual-studiobuildversioning

提问by The Light

I have a Visual Studio 2010 project and I have referenced an assembly Oracle.DataAccess.dll which points to a local version.

我有一个 Visual Studio 2010 项目,我引用了一个指向本地版本的程序集 Oracle.DataAccess.dll。

I've explicitly set the option "Specific Version" to false but when the application is built I've checked the application assembly and it has a specific reference to the

我已经明确地将选项“特定版本”设置为 false,但是在构建应用程序时,我已经检查了应用程序程序集,并且它对

Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342

Oracle.DataAccess,版本=2.112.3.0,文化=中性,PublicKeyToken=89b483f429c47342

How not referencing a specific version of an assembly?

如何不引用程序集的特定版本?

I'd like to rely on which version version is available in the bin folder.

我想依赖 bin 文件夹中可用的版本。

It currently apparently depends on where the application is built. If I build the project on a machine that has a different version of the Oracle Client installed, then a different Oracle.DataAccess versioning reference will be in the main application.

目前显然取决于应用程序的构建位置。如果我在安装了不同版本的 Oracle 客户端的机器上构建项目,则主应用程序中将有不同的 Oracle.DataAccess 版本控制参考。

It shouldn't rely on where the application is built really. It should not reference any specific version.

它不应该依赖于应用程序的真正构建位置。它不应引用任何特定版本。

回答by Mike Zboray

Specific Version is a compile time check that the version you actually build against is the version that you actually have in the project/file reference.

特定版本是编译时检查您实际构建的版本是否是您在项目/文件引用中实际拥有的版本。

Which ever version you compiled against goes into the compiled assembly metadata as a referenced assembly. This includes the assembly version number because it is part of the assembly's identity to the CLR. There is no way to have a reference to another assembly without a version being included in the output assembly.

您编译的哪个版本作为引用的程序集进入编译的程序集元数据。这包括程序集版本号,因为它是 CLR 程序集标识的一部分。如果输出程序集中不包含版本,则无法引用另一个程序集。

For your scenario, I would probably set Specific Version to true so if I build it on a machine with a different version installed, compilation fails. Then I would update the project file if I wanted to compile against a new version.

对于您的场景,我可能会将特定版本设置为 true,因此如果我在安装了不同版本的机器上构建它,编译会失败。然后,如果我想针对新版本进行编译,我会更新项目文件。

If you want to run against a possibly newer version of the referenced assembly, that is properly controlled via policy. Either a publisher policy file, which Oracle would provide, or if you determine that your application is fully compatible with newer versions, via app config assembly binding redirection. This documentationprovides an example of redirection via config file.

如果您想针对引用程序集的可能更新版本运行,则可以通过policy正确控制。Oracle 将提供的发布者策略文件,或者如果您确定您的应用程序与较新版本完全兼容,则通过应用程序配置程序集绑定重定向。本文档提供了一个通过配置文件重定向的示例。

回答by Mario Stoilov

Well since you are refering to that .dll in the project, you cannot avoid specifying a version. If you want to call the .dll file without relying on its version you'll have to do it in your code. See this

好吧,由于您在项目中引用了该 .dll,因此您无法避免指定版本。如果您想调用 .dll 文件而不依赖其版本,则必须在代码中执行此操作。看到这个

回答by const314

If you set SpecificVersion to false, you can then easily replace the referenced assembly, it will work without any problems. The version you mentioned only indicates the version the project was build with.

如果将SpecificVersion 设置为false,则可以轻松替换引用的程序集,它可以正常工作而不会出现任何问题。您提到的版本仅表示项目构建时使用的版本。

You can easily check this behavior. Create a Class library project with one class in it that contains one public method that returns some string message. Build it and place resulting assembly in some folder from where you will reference it. Then create a console project that will reference your assembly with SpecificVersion=false and CopyLocal=true and outputh the message to console. Build it and run. After that, change the returned string in first project, change version, build and replace the assembly near your console project executable. Run again, you'll see that message is changed.

您可以轻松检查此行为。创建一个包含一个类的类库项目,该类包含一个返回一些字符串消息的公共方法。构建它并将生成的程序集放置在您将引用它的某个文件夹中。然后创建一个控制台项目,该项目将使用 SpecificVersion=false 和 CopyLocal=true 引用您的程序集,并将消息输出到控制台。构建并运行。之后,更改第一个项目中返回的字符串,更改版本,构建和替换控制台项目可执行文件附近的程序集。再次运行,您将看到该消息已更改。

回答by Wernfried Domscheit

For Oracle.DataAccess the situation is a bit special. See screenshot for my installed Oracle.DataAccess

对于 Oracle.DataAccess,情况有点特殊。查看我安装的 Oracle.DataAccess 的屏幕截图

You may install verison 1.x, 2.0 or 4.0, see available downloads here: Oracle Data Access Components (ODAC) for Windows

您可以安装版本 1.x、2.0 或 4.0,请在此处查看可用下载: 适用于 Windows 的 Oracle 数据访问组件 (ODAC)

It also depends which Oracle Client version you have installed. ODP.NET Version 1.x is available only till Oracle 11.1. Version 1.x and 2.0 are not 100% compatible to each other(but it is possbile to managed them in the same code). In VS you specify the version, e.g. 2.0. In this case you must have a version 2.x.x.x installed on your machine, in my case it will load 2.102.2.20, see policyin earlier answer. If you specify version 1.x then version 1.x.x.x must be installed on your machine. For version 4.0 I did not test yet.

它还取决于您安装的 Oracle 客户端版本。ODP.NET 1.x 版仅在 Oracle 11.1 之前可用。 版本 1.x 和 2.0 不是 100% 兼容的(但可以用相同的代码管理它们)。在 VS 中,您指定版本,例如 2.0。在这种情况下,您的机器上必须安装 2.xxx 版本,在我的情况下,它将加载 2.102.2.20,请参阅先前回答中的策略。如果您指定版本 1.x,则必须在您的机器上安装版本 1.xxx。对于 4.0 版本,我还没有测试。

In application which I develop, I provide two different Setup.exe. The customer has to select the correct setup based on his Oracle Client installation.

在我开发的应用程序中,我提供了两个不同的 Setup.exe。客户必须根据其 Oracle 客户端安装选择正确的设置。

Furter information you can find here: ODP.NET FAQ

您可以在此处找到更多信息:ODP.NET 常见问题解答

My installed Oracle.DataAccess enter image description here

我安装的 Oracle.DataAccess 在此处输入图片说明