是否有任何正式的目标框架指令?

编程入门 行业动态 更新时间:2024-10-24 18:18:24
本文介绍了是否有任何正式的目标框架指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已阅读

I've read Microsoft's article about how to detect target framework, for example :

netcoreapp2.2 net47 net58

But there are situations where I don't care about the exact version, but the general framework target :

NETCORE .Net Framework

But I didn't find such flags.

Question:

Are there any generalized flags for that ? or better, how can I distinguish between those two without specifying all options?

解决方案

Besides the version-specific directives such as NETSTANDARD2_0, the Target frameworks documentation lists the following preprocessor symbols:

  • NETFRAMEWORK

  • NETSTANDARD

  • NETCOREAPP

...and NETMF for .NET Micro Framework, WP for Windows Phone, and UAP for Universal Windows Platform.

Here is an example .csproj:

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFrameworks>netstandard1.5;netstandard2.0;net48;netcoreapp3.0</TargetFrameworks> </PropertyGroup> </Project>

and C# class:

namespace ClassLibrary1 { public class Class1 { public void Test() { #if NETFRAMEWORK System.Console.WriteLine(".NET Framework"); #elif NETCOREAPP System.Console.WriteLine(".NET Core"); #elif NETSTANDARD System.Console.WriteLine(".NET Standard"); #endif } } }

Here's .NET Core 3.0 selected (see top left), with the NETCOREAPP region 'live' and the others greyed out:

更多推荐

是否有任何正式的目标框架指令?

本文发布于:2023-11-06 07:01:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563006.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指令   框架   有任何   目标   正式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!