在C#程序中,我需要获取有关程序运行的运行时环境的信息。
基本上,我需要知道当前程序是在.NET Core还是在.NET Framework 4.x中运行。
以下内容可能有效:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.uploadSession",
"expirationDateTime": "2017-04-06T10:32:48.5252565Z",
"nextExpectedRanges": [
"0-"
],
"uploadUrl": "......."
}
但是有更好的方法吗?
答案 0 :(得分:5)
Microsoft.Extensions.PlatformAbstractions!
using Microsoft.Extensions.PlatformAbstractions;
var runtimeInfo = PlatformServices.Default.Application.RuntimeFramework;
PlatformServices.Default.Application.RuntimeFramework
属性包含诸如运行时标识符及其版本之类的信息。并且可以在.net核心上获得。
归功于:
Jurjen指出System.Environment.Version
以某种方式引导我Victor Hurdugaci发表评论
答案 1 :(得分:0)
检查System.Environment.Version
属性(http://msdn.microsoft.com/en-us/library/system.environment.version.aspx)。
public static void Main()
{
Console.WriteLine("Version: {0}", Environment.Version.ToString());
}