.NET分析工具:程序包版本与程序集版本 [英] .NET Analyzer: Package Version vs Assembly Version

查看:36
本文介绍了.NET分析工具:程序包版本与程序集版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如下图所示,当您使用VS 2017创建带有代码修复(.NET Standard)的Analyzer类型的项目时,在项目的属性选项卡中有程序包版本,程序集版本和程序集文件版本.

这3个版本是否相互关联?另外,当我在项目中进行更改时,应该如何更改版本号?例如,如果我修复了错误,添加了新规则等.

解决方案

这3个版本是否相互关联?另外,当我在项目中进行更改时,应该如何更改版本号?例如,如果我修复了错误,添加了新规则等.

在回答此问题之前,我们需要了解有关 AssemblyVersion AssemblyFileVersion 的一些信息.

程序集版本:这是.Net在运行时用于加载程序包和查找类型的版本.

组装文件版本::它定义了操作系统报告给Windows Explorer等其他应用程序的版本.

您可以看到

保存后,可以在 MyProject.csproj 中找到这些值:

 < Project Sdk ="Microsoft.NET.Sdk">< PropertyGroup>< TargetFramework> net461</TargetFramework><版本> 1.2.3.4</版本>< Authors>作者1</Authors><公司>公司XYZ</公司><产品>产品2</产品>< PackageId> MyApp</PackageId>< AssemblyVersion> 2.0.0.0</AssemblyVersion>< FileVersion> 3.0.0.0</FileVersion>< NeutralLanguage> en</NeutralLanguage><说明>此处说明</说明><版权>版权</版权>< PackageLicenseUrl>许可证URL</PackageLicenseUrl>< PackageProjectUrl>项目URL</PackageProjectUrl>< PackageIconUrl>图标URL</PackageIconUrl>< RepositoryUrl>存储库URL</RepositoryUrl>< RepositoryType>存储库类型</RepositoryType>< PackageTags>标签</PackageTags>< PackageReleaseNotes>发布</PackageReleaseNotes></PropertyGroup> 

在文件资源管理器属性信息选项卡中,版本显示为产品版本",供NuGet使用.就像版本控制属性一样: AssemblyInformationalVersion .

因此,如果您修复了错误或添加了新规则,则可以更改软件包版本以运送新软件包.

重大更改增加为大,较小更改增加为向后兼容,并修复了一些错误.

关于是否需要修改程序集版本的版本号,可以参考 解决方案

Are those 3 versions related together or not? Also, as I make changes in the project how am I supposed to change the versions number? For instance, if I fix a bug, if I add a new rule, etc.

Before answering this question, we need to know some info about the AssemblyVersionand AssemblyFileVersion.

Assembly Version: This is the version that .Net looks at during run-time for loading packages and finding types.

Assembly File Version: This defines the version reported by the OS to other applications like Windows Explorer.

You can see the Rémy van Duijkeren`s answer for some more details.

However, NuGet doesn’t use either of these. It uses a third versioning attribute: AssemblyInformationalVersion - the Product version of the assembly.

It uses this attribute because nothing else seems to care about it. The informational version isn’t used by the OS or by .Net, which means it’s available for NuGet to claim. But this versioning attribute was removed in the AssemblyInfo.cs file, because they don’t apply to semantic versioning.

When you are in the project of type Analyzer with Code Fix (.NET Standard) using VS 2017, those attributes settings has moved into the .csproj file. By default they don't show up but you can discover them from Visual Studio 2017 in the project properties Package tab:

Once saved those values can be found in MyProject.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
    <Version>1.2.3.4</Version>
    <Authors>Author 1</Authors>
    <Company>Company XYZ</Company>
    <Product>Product 2</Product>
    <PackageId>MyApp</PackageId>
    <AssemblyVersion>2.0.0.0</AssemblyVersion>
    <FileVersion>3.0.0.0</FileVersion>
    <NeutralLanguage>en</NeutralLanguage>
    <Description>Description here</Description>
    <Copyright>Copyright</Copyright>
    <PackageLicenseUrl>License URL</PackageLicenseUrl>
    <PackageProjectUrl>Project URL</PackageProjectUrl>
    <PackageIconUrl>Icon URL</PackageIconUrl>
    <RepositoryUrl>Repo URL</RepositoryUrl>
    <RepositoryType>Repo type</RepositoryType>
    <PackageTags>Tags</PackageTags>
    <PackageReleaseNotes>Release</PackageReleaseNotes>
  </PropertyGroup>

In the file explorer properties information tab, Version is shown as "Product version", which is used by NuGet. Just like the versioning attribute: AssemblyInformationalVersion.

So, if you fix a bug or add a new rule, you can change the package version for shipping new package.

major is incremented for a breaking change, minor for a change that is backwards compatible and patch for bug fixes.

As to whether it needs to be modified the versions number for Assembly Versions, you can refer to this document for some more details.

Hope this helps.

这篇关于.NET分析工具:程序包版本与程序集版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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