Search code examples
version.net-assembly.net-core

Display project version in ASP.NET Core 1.0.0 web application


None of what used to work in RC.x helps anymore.

I have tried these:

  1. PlatformServices.Default.Application.ApplicationVersion;

  2. typeof(Controller).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;

  3. Assembly.GetEntryAssembly().GetName().Version.ToString();

They all return 1.0.0.0 instead of 1.0.0-9 which should be after execution of the dotnet publish --version-suffix 9 having this in project.json: "version": "1.0.0-*"

Basically they give me "File version" from the attached picture instead of "Product version" which dotnet publish actually seems to change.

enter image description here


Solution

  • For version 1.x:

    Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
    

    For version 2.0.0 this attribute contains something ugly: 2.0.0 built by: dlab-DDVSOWINAGE041 so use this one:

    typeof(RuntimeEnvironment).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;