究竟怎样的"特定版本"在Visual Studio中集引用的工作性质? [英] How exactly does the "Specific Version" property of an assembly reference work in Visual Studio?

查看:315
本文介绍了究竟怎样的"特定版本"在Visual Studio中集引用的工作性质?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我有一个仔细看看程序集引用了特定版本属性在Visual Studio 2010中经过几次实验,意外的结果我开始学习尽可能多的有关属性如何工作。即便如此,在我看来,没有所有的答案,所以这里是我的尝试自我回答这个问题:

Today I had a closer look at the "Specific Version" property of assembly references in Visual Studio 2010. After a few experiments with unexpected results I set out to learn as much as possible about how the property works. Even SO, it appears to me, does not have all the answers, so here is my attempt at self-answering the question:

如何完全确实在Visual Studio中的程序集引用作品的特定版本属性?

How exactly does the "Specific Version" property of an assembly reference work in Visual Studio?

推荐答案

一个知道最重要的事情是,特定版本是一个属性才会生效的编译时间不可以在运行时。

It's a compile-time property!

One of the most important things to know is that "Specific Version" is a property that takes effect at compile-time and not at runtime.

在项目建成后,该项目的组件需要引用,以便发现构建系统应该使用物理组件加以解决。如果执行了特定版本检查(见当是特定版本检查?),它会影响大会决议过程的结果:

When a project is built, the project's assembly references need to be resolved in order to find the physical assemblies that the build system should use. If the "Specific Version" check is performed (see section "When is "Specific Version" checked?"), it affects the outcome of the assembly resolution process:

  • 在构建系统定位的物理组件,它能够潜在地使用
  • 在构建系统中的物理组件的版本进行比较,以存储在.csproj的文件中的程序集引用程序集的版本
  • 如果这两个组件的版本是完全一样的,在解决过程成功,发现物理组件用于构建
  • 如果这两个组件的版本不匹配,物理组件被丢弃,解析过程继续通过定位在未来潜在的组装
  • 如果没有更多的潜在的物理组件可以被定位,解析过程失败。这将导致一个编译器(报警MSB3245),告诉您参考无法得到解决。
  • 有趣的是,构建然后继续!如果在code没有实际引用到装配,构建成功(与previously提到的警告)。如果code的引用文件,其构建失败,看起来仿佛code用未知的类型或命名空间的错误。唯一的指示为何生成的真正的失败是警告MSB3245。
  • The build system locates a physical assembly that it can potentially use
  • The build system compares the physical assembly's version to the assembly version stored in the .csproj file for the assembly reference
  • If the two assembly versions are exactly the same, the resolution process succeeds and the physical assembly found is used for the build
  • If the two assembly versions do not match, the physical assembly is discarded and the resolution process continues by locating the next potential assembly
  • If no more potential physical assemblies can be located, the resolution process fails. This results in a compiler warning (warning MSB3245) that tells you that the reference could not be resolved.
  • Interestingly enough, the build then continues! If the code has no actual references to the assembly, the build succeeds (with the previously mentioned warning). If the code has references, the build fails with an error that looks as if the code were using unknown types or namespaces. The only indication why the build really failed is the warning MSB3245.

在其中大会决议过程中找到潜在的组件的顺序似乎是这样的:

The order in which the assembly resolution process locates potential assemblies appears to be this:

  1. &LT引用的组件; HintPath> 元素在.csproj的文件
  2. 在该项目的输出路径
  3. 海关总署
  1. The assembly referenced by the <HintPath> element in the .csproj file
  2. The project output path
  3. The GAC

请注意,如果在GAC中存在的几个版本的组件,该解决过程首先尝试解析到组装的最高版本。这是重要的仅在特定版本未进行检查。

Note that if several versions of the assembly exist in the GAC, the resolution process first attempts to resolve to the assembly with the highest version. This is important only if the "Specific Version" check is not made.

Visual Studio中据以决定是否执行了特定版本检查两条信息中的.csproj文件中找到:

Visual Studio bases its decision whether to perform the "Specific Version" check on two pieces of information found in the .csproj file:

  • 的presence与否&LT的; SpecificVersion&GT; 元素,它的值(如果它是present)
  • 的$ P $在装配参考psence与否的版本信息
  • The presence or absence of the <SpecificVersion> element, and its value (if it is present)
  • The presence or absence of version information in the assembly reference

这是如何使用的版本信息,一个典型的集引用的样子(由我添加了更好的可读性换行):

This is how a typical assembly reference with version information looks like (line break added by me for better readability):

<Reference Include="Foo, Version=1.2.3.4, Culture=neutral,
                         processorArchitecture=MSIL">
  <SpecificVersion>True</SpecificVersion>
  <HintPath>..\..\Bar\Foo.dll</HintPath>
</Reference>

这是怎样的程序集的引用样子的没有的版本信息:

<Reference Include="Foo">
[...]

下表显示当执行特定版本检查,而当它不是

The following table shows when the "Specific Version" check is performed, and when it is not.

                            |     Version information
                            |  Present       Not present
----------------------------+------------------------------
<SpecificVersion>           |
- Present, has value True   |    Yes (1)        Yes (check always fails) (2)
- Present, has value False  |    No  (3)        No (4)
- Not present               |    Yes (5)        No (6)

在这里令人惊讶的是,没有进行任何检查,如果两个&LT; SpecificVersion&GT; 和版本信息不存在(案例6)。我本来预计将因为在我的理解进行了检查,并总是失败(相同的情况下2)没有&LT; SpecificVersion&GT; 意味着默认值真 。这可能是Visual Studio 2010中,我做了我的测试的怪癖。

The surprising thing here is that no check is performed if both <SpecificVersion> and version information are absent (case 6). I would have expected the check to be performed and to always fail (same as case 2) because in my understanding the absence of <SpecificVersion> implies the default value "True". This may be a quirk of Visual Studio 2010 where I did my tests.

当您检查在Visual Studio的用户界面的程序集引用的属性(选择的参考和打F4),你看到了特定版本属性的值告诉你的Visual Studio是否要执行的具体版本检查。如果6的用户界面将显示真,虽然&LT; SpecificVersion&GT; 元素不是present在.csproj的文件

When you examine the properties of an assembly reference in the Visual Studio UI (select the reference and hit F4), the value you see for the "Specific Version" property tells you whether or not Visual Studio is going to perform the "Specific Version" check. In case 6 the UI will show "True", although the <SpecificVersion> element is not present in the .csproj file.

如果在复制本地属性设置为真,但大会决议过程中失败的原因是特定版本的检查,没有装配被复制。

If the "Copy Local" property is set to "True" but the assembly resolution process fails because of the "Specific Version" check, no assembly is copied.

  • What you need to know about referenced assemblies in VS2005 (blogs.msdn.com article)
  • What's New in .NET 2.0 for Assemblies and Versioning? (codemag.com article which reproduces the above MSDN article, down to the wording, but contains a few screenshots and additional information about assembly versioning)

这篇关于究竟怎样的&QUOT;特定版本&QUOT;在Visual Studio中集引用的工作性质?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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