[英].NET framework in #if statement for compilation is not identifying net461
我有 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 核心。 所以我只是做了以下
#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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.