Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Analyzer: Package Version vs Assembly Version

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.

enter image description here

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.

like image 348
Mo Sadeghipour Avatar asked Mar 03 '18 12:03

Mo Sadeghipour


1 Answers

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:

enter image description here

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.

like image 155
Leo Liu-MSFT Avatar answered Oct 19 '22 19:10

Leo Liu-MSFT