简体   繁体   English

“转到定义”版本号从何而来?

[英]Where does the “Go To Definition” version number come from?

In Visual Studio 2019, if you right click on a symbol, you can select "Go To Definition".在 Visual Studio 2019 中,如果右键单击某个符号,则可以选择“转到定义”。 If the symbol is not defined in your code, it will attempt to generate the code from the dll.如果该符号未在您的代码中定义,它将尝试从 dll 生成代码。

When it generates this file, it puts a #region comment at the top of it.当它生成这个文件时,它会在它的顶部放置一个#region注释。 This is an example of what my region comment looks like:这是我的地区评论的示例:

#region Assembly Logging.Client, Version=6.0.1.0, Culture=neutral, PublicKeyToken=null
// C:\Users\myUserId\.nuget\packages\logging.client\7.0.0.43\lib\netstandard2.0\Logging.Client.dll
#endregion

The key part is that it says Version=6.0.1.0 .关键部分是它说Version=6.0.1.0 I opened up the NuGet file, and, on the properties of Logging.Client.dll, the version says 7.0.0.43:我打开了 NuGet 文件,在 Logging.Client.dll 的属性上,版本显示为 7.0.0.43:

Logging.Client.dll 的属性

So, my question is: Where does the version number shown on the line of the #region comment get pulled from?所以,我的问题是: #region注释行中显示的版本号从哪里提取的?

NOTE: I looked at this similar question, but the steps of deleting the existing packages, restarting Visual Studio and rebuilding did not resolve my issue: Latest version of nuget package still not up to date注意:我查看了这个类似的问题,但是删除现有包、重新启动 Visual Studio 和重建的步骤并没有解决我的问题: 最新版本的 nuget 包仍然不是最新的

Where does the “Go To Definition” version number come from? “转到定义”版本号从何而来?

It is from AssemblyVerion attribute on VS and it is set in your nuget project by the nuget author.它来自 VS 上的AssemblyVerion属性,由 nuget 作者在您的 nuget 项目中设置。

Please see the below interpretation.请看下面的解释。

=================================================================== ================================================== ==================

I assume that logging.client nuget package is your own nuget package.(created by yourself)我假设logging.client nuget 包是您自己的 nuget 包。(由您自己创建)

This is a normal behavior of the nuget and assembly mechanism.这是 nuget 和程序集机制的正常行为。 It is not an issue and it is just defined that way by the author of the package.这不是问题,它只是由包的作者定义的。

These make sense and are defined by the author when the nuget package is created and can be modified by the author.这些是有意义的,并且是在创建 nuget 包时由作者定义的,并且可以由作者进行修改。 It's just that they have different functions from each other to deal with the mechanism of nuget.只是它们在处理nuget的机制上各有不同的功能。

The Version=6.0.1.0 is the assembly version of the dll which used by framework. Version=6.0.1.0是框架使用的dll的汇编版本。 It is a built-in version number which is used during build or used at runtime.它是一个内置版本号,在构建期间使用或在运行时使用。 It can only be accessed by vs internally.它只能由 vs 内部访问。 To be precise , this is its real version number.准确地说,这是它的真实版本号。

And File Version 7.0.0.43 is the version of the dll, which is used for external display and can be accessed externally.File Version 7.0.0.43是dll的版本,用于外部显示,可以外部访问。

And Product Version 7.0.0.43 means the nuget package version which also can access outside VS.Product Version 7.0.0.43表示也可以在 VS 外部访问的 nuget 包版本。

So, they all are defined by the author as he want.所以,它们都是由作者定义的。

See this official document about the function of these attributes: Use AssemblyVersion and AssemblyFileVersion attributes .有关这些属性的功能,请参阅此官方文档:使用 AssemblyVersion 和 AssemblyFileVersion 属性

They all have professional terms in VS:他们在VS中都有专业术语:

AssemblyVersion means 6.0.1.0 , AssemblyFileVersion means File Version 7.0.0.43 and NugetVersion means Product Version 7.0.0.43 . AssemblyVersion表示6.0.1.0 , AssemblyFileVersion 表示File Version 7.0.0.43NugetVersion表示Product Version 7.0.0.43 And they can be also access outside VS.而且它们也可以在 VS 之外访问。

==================================================== ================================================== ==

In my side , I created a net standarad class library project called ClassLibrary1 .在我这边,我创建了一个名为ClassLibrary1net standarad类库项目。

Right-click on your net standard class library project, right-click on your project Properties --> Package右键单击您的net standard类库项目,右键单击您的项目属性-->

包属性对话框包括包版本、程序集版本和程序集文件版本。

1) 1)

The Assembly version is used under Logging.Client, Version=6.0.1.0, Culture=neutral, PublicKeyToken=null .Logging.Client, Version=6.0.1.0, Culture=neutral, PublicKeyToken=null下使用Assembly 版本

When you install that package on the main project, on the main project, click on the dll on the References and you will see the internal version 6.0.1.0 under the Properties Window.当您在主项目上安装该包时,在主项目上,单击References上的 dll,您将在“属性”窗口下看到内部版本6.0.1.0

And when you install this package on a net framework project with packages.config , it will shows on the csproj file:当您使用packages.confignet framework项目上安装此包时,它将显示在csproj文件中:

<ItemGroup>
    <Reference Include="ClassLibrary1, Version=6.0.1.0, Culture=neutral, processorArchitecture=MSIL">
        <HintPath>..\packages\ClassLibrary1.7.0.0.43\lib\netstandard2.0\ClassLibrary1.dll</HintPath>
    </Reference>

The version is used by the internal framework and at build or runtime and only be seen in VS.该版本由内部框架在构建或运行时使用,并且只能在 VS 中看到。

2) 2)

The Assembly File version is the file name, it shows on the dll's properties and shows outside VS as File Version which you described on the case.程序集文件版本是文件名,它显示在 dll 的属性上,并在 VS 外部显示为您在案例中描述的文件版本

3) 3)

The Package Version is the version of the nuget package rather than the assembly dll version.包版本是 nuget 包的版本,而不是程序集 dll 版本。 They're different concepts.他们是不同的概念。

In your side , it shows like this:在你身边,它显示如下:

<ItemGroup>
    <Reference Include="ClassLibrary1, Version=6.0.1.0, Culture=neutral, processorArchitecture=MSIL">
        <HintPath>..\packages\ClassLibrary1.7.0.0.43\lib\netstandard2.0\ClassLibrary1.dll</HintPath>
    </Reference>

And in the dll's properties, it shows as Product Version .在 dll 的属性中,它显示为Product Version

Overall ,it is not an issue and each of them has a meaningful and specific function.总的来说,这不是问题,它们每个都有一个有意义和特定的功能。 If you want to change this, you should change your nuget project's Properties --> Package as I said above, modify them as the same.如果你想改变这一点,你应该改变你的 nuget 项目的Properties --> Package正如我上面所说的,修改它们一样。 Then, repack its as nuget package.然后,将其重新打包为 nuget 包。

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

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