在核心CLR中的Environment.Version等同于什么?

3
以下代码适用于dnx451框架,但不适用于dnxcore50
string ver = Environment.Version

该方法不存在:

enter image description here

在dnxcore50框架中是否有相应的属性?

更新

根据Victors的答案,您可以使用PlatformServices.Default.Runtime,例如:

Console.WriteLine("env: {0} {1}", PlatformServices.Default.Runtime.RuntimeType, PlatformServices.Default.Runtime.RuntimeVersion);

输出结果:(在dnx451上)

环境:Clr 1.0.0-rc1-16231

输出结果:(在dnxcore50上)

环境:CoreClr 1.0.0-rc1-16231


它对应于文档。看起来Version属性已经被删除了。 - Oleg
1个回答

2

您可以使用IRuntimeEnvironment中的属性来获取有关运行时的信息。以下属性可用:

  • RuntimeType(运行时类型)
  • RuntimeArchitecture(运行时体系结构)
  • RuntimeVersion(运行时版本)
  • RuntimePath(运行时路径)

...并使用 new DefaultRuntimeEnvironment().RuntimeVersion ?? - wal
Microsoft.Extensions.PlatformAbstractions.dll 在 rc1 中不包含 DefaultRuntimeEnvironment - 请问您能详细说明一下它的工作原理吗? - wal
1
使用 PlatformServices.Default.Runtime。这里有一个例子:https://github.com/aspnet/Testing/blob/1.0.0-rc1/src/Microsoft.AspNet.Testing/TestPlatformHelper.cs#L11 - Victor Hurdugaci
1
这是我在使用dotnet core 1.1时所用的代码:Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.RuntimeFramework.Version,需要先安装nuget包Microsoft.Extensions.PlatformAbstractions。 - LosManos

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接