【发布时间】:2018-10-27 22:06:21
【问题描述】:
我有 2 个控制台应用程序。一个在 .Net Core 2 中,一个在 .Net 461 中
我正在尝试确定我正在运行什么框架
如果我能够识别 .net 核心但它无法确定它 对于我的 .net 461 应用程序
我是否需要为 .net 框架添加其他信息
这是我所拥有的:
#if NET461
Console.WriteLine("hello from net NET461"); // expecting this to execute, but it does not
#endif
#if NETCOREAPP2_0
Console.WriteLine("hello from net Core");
#endif
#if NETSTANDARD2_0
Console.WriteLine("hello from net NETSTANDARD2_0");
#endif
更新
虽然我没有得到我想要的\预期的结果。我真的只需要知道它是否正在运行.net core。所以我只是做了以下
#if NETCOREAPP2_0
Console.WriteLine("hello from .Net Core");
#else
Console.WriteLine("hello from Not .Net Core");
#endif
感谢大家的回复
【问题讨论】:
-
但它不适用于我的 .net 461 应用程序如果您能提供有关“不工作”含义的更多详细信息会有所帮助。理想情况下,您将提供minimal reproducible example 和示例产生的输出指示以及所需输出的指示。有关提出有效问题的更多提示,请参阅 How to Ask。
-
你得到了什么输出,你期望得到什么值?
-
Environment.Version返回什么? docs.microsoft.com/en-us/dotnet/framework/migration-guide/… 返回什么? -
@You are still 没有回答我的问题,当你运行它时你什么都没有得到,或者你得到的消息不是“你好来自net NET461"?
标签: c# .net .net-core .net-standard