.NET Analyzer: Package Version vs Assembly Version

假如想象 提交于 2020-07-18 17:49:17

问题


As you can see in the following picture when you create a project of type Analyzer with Code Fix (.NET Standard) using VS 2017, in the properties tab of the project there is package version, assembly version and assembly file version.

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.


回答1:


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.



来源:https://stackoverflow.com/questions/49084052/net-analyzer-package-version-vs-assembly-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!