显示项目版本的ASP.NET MVC核心应用(RC2) [英] Display project version in ASP.NET MVC Core application (RC2)

查看:309
本文介绍了显示项目版本的ASP.NET MVC核心应用(RC2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从project.json显示应用程序的版本?
我使用吞掉凸点来自动增量版本,但我不能显示最新版本。下面是我尝试:

<$p$p><$c$c>@(Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationVersion)

这是不行的,它会显示 1.0.0 ,而不是从实际值 project.json

我也试过,但它看起来不再在RC2作品:

  @Inject Microsoft.Extensions.PlatformAbstractions.IApplicationEnvironment appEnv
我的版本号是@(appEnv.ApplicationVersion)


解决方案

根据 IApplicationEnvironment 不再存在。

您仍可以访问 ApplicationVersion 静态使用:

<$p$p><$c$c>Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationVersion


这为我工作。我的 project.json 是这样的:

  {
    版本:1.0.0.2,
    // 其他的
}

在我的索引视图,我在顶部以下行:

<$p$p><$c$c>@Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationVersion

和我正确地获得 1.0.0.2 输出。当我改变的价值和重启(版本)的应用,新的版本显示在那里。

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)

解决方案

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.

这篇关于显示项目版本的ASP.NET MVC核心应用(RC2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆