Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# #if编译语句中的.NET framework未标识net461_C#_.net_.net Core_.net Standard - Fatal编程技术网

C# #if编译语句中的.NET framework未标识net461

C# #if编译语句中的.NET framework未标识net461,c#,.net,.net-core,.net-standard,C#,.net,.net Core,.net Standard,我有两个控制台应用程序。一个在.Net Core 2中,一个在.Net 461中 我正在尝试确定我正在运行的框架 在这种情况下,我能够识别.net核心,但它无法确定它 对于我的.net 461应用程序 是否需要为.net framework添加其他信息 以下是我所拥有的: #if NET461 Console.WriteLine("hello from net NET461"); // expecting this to execute, but it does not #endif #

我有两个控制台应用程序。一个在.Net Core 2中,一个在.Net 461中

我正在尝试确定我正在运行的框架

在这种情况下,我能够识别.net核心,但它无法确定它 对于我的.net 461应用程序

是否需要为.net framework添加其他信息

以下是我所拥有的:

#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
更新

虽然我没有得到我想要\期望的结果。我只需要知道它是否在运行.NETCore。所以我只做了以下几件事

#if NETCOREAPP2_0
   Console.WriteLine("hello from .Net Core");
#else
   Console.WriteLine("hello from Not .Net Core");
#endif

感谢所有的回复

我发现csproj的结构也很重要。这对我有用

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>

</Project>

Exe
net461

但它对我的.net 461应用程序不起作用。如果您能提供更多关于“不起作用”含义的详细信息,将会有所帮助。理想情况下,您应该提供示例生成的输出和所需输出的指示。有关提出有效问题的更多提示,请参阅。作为输出,您得到了什么?您希望得到什么价值?环境。版本返回什么?返回的是什么?可能重复的@You仍然没有回答我的问题,当你运行它时,除了“hello from net 461”之外,你是否什么也没有得到,或者你是否收到了一条消息?请解释这是怎么回事?这不是标准生成的吗?在Visual Studio 2019中,当我创建一个新项目“Console App(.Net Framework)”时,我没有得到这种类型的csproj格式。我得到了一些包含第4.6.1版这一行的东西,在本例中,如果NET461不能工作。