如何知道我是在.NET Framework还是.NET Core下运行

问题描述 投票:0回答:1

说我有一个在Nuget中的库,该库已编译为netstandard2.0以支持netcoreapp2.1net471

现在,在编译时,我不知道我是否在net471netcoreapp2.1netstandard2.0]下运行(我强调这一点,因为我不能只将自己的dll编译成两个[ C0]和netstandard,因为如果调用程序集net471,我仍然不知道输入程序集)。

我怎么知道在运行时

我正在运行哪个TargetFramwork?

我知道有这样的解决方案:

netstandard2.0

但是如果您在MSTest和Assembly.GetEntryAssembly()? .GetCustomAttribute<TargetFrameworkAttribute>()? .FrameworkName net471中运行此程序,那么我不想在使用我的Nuget的项目中破坏测试。

说我有一个在Nuget中的库,该库已编译为netstandard2.0以支持netcoreapp2.1和net471。现在,在编译时,我不知道我是在net471,netcoreapp2.1还是netstandard2下运行。...

c# .net-core .net-assembly
1个回答
1
投票

[我认为您可以使用System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription API,它是.NET Standard 1.1+和.NET Core 1.0+的一部分,也请参见Assembly.GetEntryAssembly() == null

© www.soinside.com 2019 - 2024. All rights reserved.