Display project version in ASP.NET MVC Core application (RC2)

vmg picture vmg · Jun 13, 2016 · Viewed 15.9k times · Source

How do I display application version from the project.json? I am using gulp-bump to autoincrement version, but I can't show the recent version. Here is what I'm trying:

@(Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationVersion)

This does not work, it displays "1.0.0" instead of real value from project.json

I also tried this but it looks like it is no longer works in RC2:

@inject Microsoft.Extensions.PlatformAbstractions.IApplicationEnvironment appEnv
My version number is @(appEnv.ApplicationVersion)

Answer

Luca picture Luca · Aug 17, 2017

Since Platform Abstractions were obly shipped with ASP.NET Core 1 and has been removed from ASP.NET Core 2 and up, if you're using version 2 or above, you must replace this row:

Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationVersion

with this one:

System.Reflection.Assembly.GetEntryAssembly().GetName().Version

as specified in "Replacing API usage" section of the previous linked page.