C#获取当前运行时环境信息

目录

获取框架信息,操作系统信息

csharp 复制代码
   //.net 框架信息
   var kkk = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;

   //获取应用程序多少位
   var bbb = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture;

   //获取操作系统 多少位?x64? x86?
   var ccc = System.Runtime.InteropServices.RuntimeInformation.OSArchitecture;

   //获取操作系统信息
   var aaa = System.Runtime.InteropServices.RuntimeInformation.OSDescription;

返回结果1:

bash 复制代码
.NET Framework 4.8.9181.0
X64
X64
Microsoft Windows 10.0.22621 

获取当前堆栈跟踪信息,可用于判断是否为单元测试

csharp 复制代码
//当前堆栈跟踪信息,可以判断是否在"单元测试模式"里面;
string stackTrace = System.Environment.StackTrace;

//true则为单元测试环境下,false不是
bool unitTest = System.Environment.StackTrace.IndexOf("NUnit.Framework", StringComparison.CurrentCultureIgnoreCase) >= 0;

//true则为单元测试环境下,false不是
bool uniTest2=System.Environment.StackTrace.IndexOf("TestPlatform.MSTest", StringComparison.CurrentCultureIgnoreCase) >= 0;

返回结果2:

bash 复制代码
在 System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   在 System.Environment.get_StackTrace()
   在 UnitTestProject1.UnitTest3.<TestPdf>d__20.MoveNext() 位置 E:\Work\信息报送\zhi_mi_kt_information\V4_WxPush\WuZiFenGongSiInfomation\UnitTestProject1\UnitTest3.cs:行号 344
   在 System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
   在 UnitTestProject1.UnitTest3.TestPdf()
   在 System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   在 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   在 Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Extensions.MethodInfoExtensions.InvokeAsSynchronousTask(MethodInfo methodInfo, Object classInstance, Object[] parameters)
   在 Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action action)
   在 Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestMethodInfo.ExecuteInternal(Object[] arguments)
   在 Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestMethodInfo.Invoke(Object[] arguments)
   在 Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute.Execute(ITestMethod testMethod)
   在 Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestMethodRunner.RunTestMethod()
   在 Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestMethodRunner.Execute()
   在 Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.UnitTestRunner.RunSingleTest(TestMethod testMethod, IDictionary`2 testRunParameters)
相关推荐
SteveDraw1 小时前
C++动态链接库封装,供C#/C++ 等编程语言使用——C++动态链接库概述(总)
开发语言·c++·c#·封装·动态链接库
Kookoos2 小时前
性能剖析:在 ABP 框架中集成 MiniProfiler 实现性能可视化诊断
后端·c#·.net·abp vnext·miniprofiler
阿翰4 小时前
自动 GitHub Readme 20 种语言翻译平台 - OpenAiTx 开源免费
c#·.net
枫叶kx8 小时前
1Panel运行的.net程序无法读取系统字体(因为使用了docker)
c#
军训猫猫头13 小时前
96.如何使用C#实现串口发送? C#例子
开发语言·c#
不爱写代码的玉子15 小时前
HALCON透视矩阵
人工智能·深度学习·线性代数·算法·计算机视觉·矩阵·c#
开开心心就好18 小时前
高效Excel合并拆分软件
开发语言·javascript·c#·ocr·排序算法·excel·最小二乘法
一名用户19 小时前
unity实现自定义粒子系统
c#·unity3d·游戏开发
钢铁男儿21 小时前
C# 类和继承(扩展方法)
java·servlet·c#
爱炸薯条的小朋友21 小时前
C#由于获取WPF窗口名称造成的异常报错问题
windows·c#·wpf