简体   繁体   English

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

[英]How not to reference a specific version of an assembly?

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 我已经明确地将选项“Specific Version”设置为false但是在构建应用程序时我已经检查了应用程序程序集并且它具有对

Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342 Oracle.DataAccess,Version = 2.112.3.0,Culture = neutral,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 Client的计算机上构建项目,则主应用程序中将包含不同的Oracle.DataAccess版本控制引用。

It shouldn't rely on where the application is built really. 它不应该依赖于应用程序的构建位置。 It should not reference any specific version. 它不应该引用任何特定版本。

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. 这包括程序集版本号,因为它是程序集与CLR的标识的一部分。 There is no way to have a reference to another assembly without a version being included in the output assembly. 如果输出程序集中没有包含版本,则无法引用另一个程序集。

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. 对于您的场景,我可能会将Specific Version设置为true,因此如果我在安装了不同版本的计算机上构建它,则编译将失败。 Then I would update the project file if I wanted to compile against a new version. 然后,如果我想针对新版本进行编译,我会更新项目文件。

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. Oracle提供的发布者策略文件,或者您通过app config程序集绑定重定向确定应用程序与较新版本完全兼容的文件。 This documentation provides an example of redirection via config file. 文档提供了通过配置文件进行重定向的示例。

Well since you are refering to that .dll in the project, you cannot avoid specifying a version. 好吧,既然您在项目中引用了.dll,则无法避免指定版本。 If you want to call the .dll file without relying on its version you'll have to do it in your code. 如果要在不依赖其版本的情况下调用.dll文件,则必须在代码中执行此操作。 See this 看到这个

If you set SpecificVersion to false, you can then easily replace the referenced assembly, it will work without any problems. 如果将SpecificVersion设置为false,则可以轻松替换引用的程序集,它可以正常工作。 The version you mentioned only indicates the version the project was build with. 您提到的版本仅表示项目的构建版本。

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. 然后创建一个控制台项目,它将使用SpecificVersion = false和CopyLocal = true引用您的程序集,并将消息输出到控制台。 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. 再次运行,您将看到该消息已更改。

For Oracle.DataAccess the situation is a bit special. 对于Oracle.DataAccess,情况有点特殊。 See screenshot for my installed 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 您可以安装verison 1.x,2.0或4.0,请参阅此处的可用下载: 适用于Windows的Oracle数据访问组件(ODAC)

It also depends which Oracle Client version you have installed. 它还取决于您安装的Oracle客户端版本。 ODP.NET Version 1.x is available only till Oracle 11.1. ODP.NET版本1.x仅在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). 版本1.x和2.0彼此不是100%兼容 (但可以在相同的代码中管理它们)。 In VS you specify the version, eg 2.0. 在VS中指定版本,例如2.0。 In this case you must have a version 2.xxx installed on your machine, in my case it will load 2.102.2.20, see policy in earlier answer. 在这种情况下,您的计算机上必须安装2.xxx版本,在我的情况下,它将加载2.102.2.20,请参阅前面的答案中的策略 If you specify version 1.x then version 1.xxx must be installed on your machine. 如果指定版本1.x,则必须在计算机上安装版本1.xxx。 For version 4.0 I did not test yet. 对于4.0版,我还没有测试。

In application which I develop, I provide two different Setup.exe. 在我开发的应用程序中,我提供了两个不同的Setup.exe。 The customer has to select the correct setup based on his Oracle Client installation. 客户必须根据其Oracle客户端安装选择正确的设置。

Furter information you can find here: ODP.NET FAQ 您可以在此处找到更多信息: ODP.NET常见问题解答

My installed Oracle.DataAccess 我安装了Oracle.DataAccess 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM