Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
499 views
in Technique[技术] by (71.8m points)

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

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...