【问题标题】:How to check the version of .NET Core in a deployed app?如何在已部署的应用程序中检查 .NET Core 的版本?
【发布时间】:2019-04-15 20:56:38
【问题描述】:

我正在尝试查询编译我的 Web 应用程序的 .NET Core 版本。该应用程序部署在具有 Linux 4.9.28-v7+ armv7l 的 Raspberry Pi 2 上。没有看到明显的方法。

这可能吗?

【问题讨论】:

标签: linux asp.net-core .net-core raspberry-pi raspberry-pi2


【解决方案1】:

你可以使用下面的sn-p:

var framework = Assembly
    .GetEntryAssembly()?
    .GetCustomAttribute<TargetFrameworkAttribute>()?
    .FrameworkName;

var stats = new
{                
    OsPlatform = System.Runtime.InteropServices.RuntimeInformation.OSDescription,
    AspDotnetVersion = framework
};

代码发现于:weblog.west-wind.com

在我的电脑上运行时返回:

Microsoft Windows 10.0.17134 
.NETCoreApp,Version=v2.1

【讨论】:

  • 应用已部署。我需要询问已部署的应用程序 - 无法更改源。
  • 如果您有权访问 dll 文件,您可以加载这些程序集。而不是调用Assembly.GetEntryAssembly() 你调用'Assembly.LoadFile("Path/too/app.dll")'
  • 如果您希望使用 http 获取 .version... 除非您创建应用程序以在 http 标头或其他内容中提供该版本,否则没有办法。这可以使用我的答案中的代码来获取版本来完成,并在每个请求上设置一个包含该数据的标头。
猜你喜欢
  • 2011-03-11
  • 2016-01-26
  • 2013-10-29
  • 2021-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-12
  • 2018-02-16
相关资源
最近更新 更多