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

As per this announcement, IApplicationEnvironment no longer exists.

You can still access the ApplicationVersion statically using:

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

It works for me. My project.json looks like this:

{
    "version": "1.0.0.2",
    // all the rest
}

And in my index view, I have the following line at the top:

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

And I correctly get 1.0.0.2 in the output. And when I change that value and restart (build) the application, the new version is shown there.


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.