Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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) 
like image 330
vmg Avatar asked Jun 13 '16 19:06

vmg


People also ask

How do I check my .NET core version?

Checking the Version of Your .Open your project's source folder and, in the address bar, type "cmd" and press Enter. It will open the command prompt with the project path. Execute the following command: dotnet --version . It will display your project's current SDK version,i.e., 2.1.

What is the version of ASP NET MVC are you using in your project?

To know detail navigate to "C:\Program Files (x86)\Microsoft ASP.NET{your MVC version}\Assemblies\System. Web. Mvc. dll" Right click and see the version.


2 Answers

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.

like image 155
Luca Avatar answered Oct 04 '22 16:10

Luca


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.

like image 40
poke Avatar answered Oct 04 '22 14:10

poke