.netassembliesattributes

What are differences between AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion?


There are three assembly version attributes. What are differences? Is it ok if I use AssemblyVersion and ignore the rest?


MSDN says:


This is a follow-up to What are the best practices for using Assembly Attributes?


Solution

  • AssemblyVersion

    Where other assemblies that reference your assembly will look. If this number changes, other assemblies must update their references to your assembly! Only update this version if it breaks backward compatibility. The AssemblyVersion is required.

    I use the format: major.minor (and major for very stable codebases). This would result in:

    [assembly: AssemblyVersion("1.3")] // in AssemblyInfo.cs
    
    <AssemblyVersion>1.3</AssemblyVersion> // in .csproj
    

    If you're following SemVer strictly then this means you only update when the major changes, so 1.0, 2.0, 3.0, etc.

    AssemblyFileVersion

    Used for deployment (like setup programs). You can increase this number for every deployment. Use it to mark assemblies that have the same AssemblyVersion but are generated from different builds and/or code.

    In Windows, it can be viewed in the file properties.

    The AssemblyFileVersion is optional. If not given, the AssemblyVersion is used.

    I use the format: major.minor.patch.build, where I follow SemVer for the first three parts and use the buildnumber of the buildserver for the last part (0 for local build). This would result in:

    [assembly: AssemblyFileVersion("1.3.2.42")] // in AssemblyInfo.cs
    
    <FileVersion>1.3.2.42</FileVersion> // in .csproj
    

    Be aware that System.Version names these parts as major.minor.build.revision!

    AssemblyInformationalVersion

    The Product version of the assembly. This is the version you would use when talking to customers or for display on your website. This version can be a string, like '1.0 Release Candidate'.

    The AssemblyInformationalVersion is optional. If not given, the AssemblyFileVersion is used.

    I use the format: major.minor[.patch] [revision as string]. This would result in:

    [assembly: AssemblyInformationalVersion("1.3 RC1")] // in AssemblyInfo.cs
    
    <InformationalVersion>1.3 RC</InformationalVersion> // in .csproj
    

    Version (or VersionPrefix and VersionSuffix)

    You can now also use <Version> (or <VersionPrefix> and <VersionSuffix>) in your project file.

    This will be used for AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion if they are not specified. It will also be used for the NuGet Package version!

    For example:

    <Version>1.3.2-beta</Version>
    // or
    <VersionPrefix>1.3.2</VersionPrefix>
    <VersionSuffix>beta</VersionSuffix>
    

    Which will result into:

    NuGetPackageVersion : 1.3.2-beta
    AssemblyVersion: 1.3.2.0
    AssemblyFileVersion: 1.3.2.0
    AssemblyInformationalVersion: 1.3.2-beta