通过


目标框架

NuGet 在各种位置使用目标框架引用来专门标识和隔离包的依赖框架的组件:

  • 项目文件:对于 SDK 样式的项目, .csproj 包含目标框架引用。
  • .nuspec 清单:包可以指示项目中包含的不同包,具体取决于项目的目标框架。
  • .nupkg 文件夹名称:包文件夹中的文件夹可以根据目标框架进行命名,每个文件夹 lib 都包含 DLL 和适合该框架的其他内容。
  • packages.configtargetframework 依赖项的属性指定要安装的包的变体。

有关所有受支持的目标框架及其 TFM 语法的规范列表,请参阅 SDK 样式项目中的目标框架

TargetFramework 值是别名

TargetFramework项目文件中的属性是一个友好名称(别名),可转换为规范框架标识。 .NET SDK 通过设置 TargetFrameworkMoniker (TFM)和属性(如果适用 TargetPlatformMoniker )来执行此转换。

例如,编写 <TargetFramework>net10.0-windows</TargetFramework>时,.NET SDK 会将该 SDK 转换为:

  • TargetFrameworkMoniker = .NETCoreApp,Version=v10.0
  • TargetPlatformMoniker = Windows,Version=7.0

NuGet 使用这些名字对象属性(而不是 TargetFramework 字符串)进行包兼容性检查。 这意味着 TargetFramework 值本身可以是任何字符串,只要正确设置名字对象属性。 例如,以下项目有效:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>banana</TargetFramework>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(TargetFramework)' == 'banana' ">
    <TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
    <TargetFrameworkMoniker>.NETCoreApp,Version=v10.0</TargetFrameworkMoniker>
  </PropertyGroup>
</Project>

即使值为 banana.NET 10.0,TargetFramework此项目也会还原和生成。 .NET SDK 已经依赖于这种特定于 OS 的 TTFM net8.0-iosnet8.0-android的别名机制,其中短 TFM 转换为具有平台信息的完整名字对象。

具有重复框架的多目标

NuGet 7.6 / .NET SDK 10.0.300 开始,多个 TargetFrameworks 别名可以解析为相同的有效框架。 这可实现多 RID 生成和多版本扩展目标等方案。 有关此操作如何适用于还原、打包、锁定文件和项目引用的详细信息,请参阅 面向多个框架

支持的框架

框架通常由短目标框架名字对象或 TFM 引用。 在 .NET Standard 中, TxM 也通用化为允许对多个框架的单个引用。

注释

在以下位置找到计算下表的 NuGet 客户端源代码:

NuGet 客户端支持下表中的框架。 等效项显示在方括号 [] 中。 请注意,某些工具(例如 dotnet)可能会在某些文件中使用规范 TPM 的变体。 例如,dotnet pack在文件中使用.NETCoreApp2.0,而不是 netcoreapp2.0.nuspec 。 各种 NuGet 客户端工具正确处理这些变体,但在直接编辑文件时,应始终使用规范 TPM。

名称 缩写 TFM/TxM
.NET Framework net11
net20
net35
net40
net403
net45
net451
net452
net46
net461
net462
net47
net471
net472
net48
Microsoft应用商店(Windows 应用商店) netcore netcore [netcore45]
netcore45 [win, win8]
netcore451 [win81]
netcore50
.NET MicroFramework netmf netmf
Windows操作系统 win [win8, netcore45]
win8 [netcore45, win]
win81 [netcore451]
win10 (Windows 10 平台不支持)
Silverlight SL sl4
sl5
Windows Phone (SL) Wp wp [wp7]
wp7
wp75
wp8
wp81
Windows Phone (UWP) wpa81
通用 Windows 平台 Uap uap [uap10.0]
uap10.0
uap10.0.xxxxx (其中 10.0.xxxxx 是消耗应用的目标平台最小版本)
.NET Standard netstandard netstandard1.0
netstandard1.1
netstandard1.2
netstandard1.3
netstandard1.4
netstandard1.5
netstandard1.6
netstandard2.0
netstandard2.1
.NET 5+ (和 .NET 核心) netcoreapp netcoreapp1.0
netcoreapp1.1
netcoreapp2.0
netcoreapp2.1
netcoreapp2.2
netcoreapp3.0
netcoreapp3.1
net5.0
net6.0
net7.0
net8.0
net9.0
net10.0
Tizen tizen tizen3
tizen4
本地 本机的 本机的

弃用的框架

以下框架已弃用。 面向这些框架的包应迁移到指示的替换项。

弃用的框架 Replacement
aspnet50 netcoreapp
aspnetcore50
dnxcore50
dnx
dnx45
dnx451
dnx452
dotnet netstandard
dotnet50
dotnet51
dotnet52
dotnet53
dotnet54
dotnet55
dotnet56
winrt

Precedence

许多框架彼此相关且相互兼容,但不一定等效:

Framework 可以使用
uap (通用 Windows 平台) Windows 8.1
wpa81
netcore50
win (Microsoft商店) winrt

.NET 标准

.NET Standard 简化了二进制兼容框架之间的引用,允许单个目标框架引用其他框架的组合。 (有关背景信息,请参阅 .NET Primer

NuGet 获取最近的框架工具模拟 NuGet 根据项目的框架从包中的多个可用框架资产中选择一个框架。

应在 dotnet NuGet 3.3 及更早版本中使用一系列名字对象; netstandard 名字对象语法应在 v3.4 及更高版本中使用。

可移植类库

警告

不建议使用 PCL。 尽管支持 PCL,但包作者应改为支持 netstandard。 .NET Platform Standard 是 PCL 的演变,它使用单个名字对象表示跨平台的二进制可移植性,该名字对象与静态库(如 可移植-a+b+c 名字对象)无关。

若要定义引用多个子目标框架的目标框架,该 portable 关键字用于为引用框架列表添加前缀。 避免人为地包括不直接编译的额外框架,因为它可能会导致这些框架中的意外副作用。

第三方定义的其他框架提供与其他以这种方式访问的环境的兼容性。 此外,有一些简写配置文件编号可用于引用这些相关框架 Profile#的组合,但不建议使用这些数字,因为它减少了文件夹和的 .nuspec可读性。

配置 文件# 框架 完全名称 .NET Standard
简介2 .NETFramework 4.0 portable-net40+win8+sl4+wp7
Windows 8.0
Silverlight 4.0
WindowsPhone 7.0
Profile3 .NETFramework 4.0 portable-net40+sl4
Silverlight 4.0
Profile4 .NETFramework 4.5 portable-net45+sl4+win8+wp7
Silverlight 4.0
Windows 8.0
WindowsPhone 7.0
Profile5 .NETFramework 4.0 portable-net40+win8
Windows 8.0
Profile6 .NETFramework 4.0.3 portable-net403+win8
Windows 8.0
Profile7 .NETFramework 4.5 portable-net45+win8 netstandard1.1
Windows 8.0
Profile14 .NETFramework 4.0 portable-net40+sl5
Silverlight 5.0
Profile18 .NETFramework 4.0.3 portable-net403+sl4
Silverlight 4.0
Profile19 .NETFramework 4.0.3 portable-net403+sl5
Silverlight 5.0
Profile23 .NETFramework 4.5 portable-net45+sl4
Silverlight 4.0
Profile24 .NETFramework 4.5 portable-net45+sl5
Silverlight 5.0
Profile31 Windows 8.1 portable-win81+wp81 netstandard1.0
WindowsPhone 8.1 (SL)
Profile32 Windows 8.1 portable-win81+wpa81 netstandard1.2
WindowsPhone 8.1 (UWP)
Profile36 .NETFramework 4.0 portable-net40+sl4+win8+wp8
Silverlight 4.0
Windows 8.0
WindowsPhone 8.0 (SL)
Profile37 .NETFramework 4.0 portable-net40+sl5+win8
Silverlight 5.0
Windows 8.0
Profile41 .NETFramework 4.0.3 portable-net403+sl4+win8
Silverlight 4.0
Windows 8.0
Profile42 .NETFramework 4.0.3 portable-net403+sl5+win8
Silverlight 5.0
Windows 8.0
Profile44 .NETFramework 4.5.1 portable-net451+win81 netstandard1.2
Windows 8.1
Profile46 .NETFramework 4.5 portable-net45+sl4+win8
Silverlight 4.0
Windows 8.0
Profile47 .NETFramework 4.5 portable-net45+sl5+win8
Silverlight 5.0
Windows 8.0
Profile49 .NETFramework 4.5 portable-net45+wp8 netstandard1.0
WindowsPhone 8.0 (SL)
Profile78 .NETFramework 4.5 portable-net45+win8+wp8 netstandard1.0
Windows 8.0
WindowsPhone 8.0 (SL)
Profile84 WindowsPhone 8.1 portable-wp81+wpa81 netstandard1.0
WindowsPhone 8.1 (UWP)
Profile88 .NETFramework 4.0 portable-net40+sl4+win8+wp75
Silverlight 4.0
Windows 8.0
WindowsPhone 7.5
Profile92 .NETFramework 4.0 portable-net40+win8+wpa81
Windows 8.0
WindowsPhone 8.1 (UWP)
Profile95 .NETFramework 4.0.3 portable-net403+sl4+win8+wp7
Silverlight 4.0
Windows 8.0
WindowsPhone 7.0
Profile96 .NETFramework 4.0.3 portable-net403+sl4+win8+wp75
Silverlight 4.0
Windows 8.0
WindowsPhone 7.5
Profile102 .NETFramework 4.0.3 portable-net403+win8+wpa81
Windows 8.0
WindowsPhone 8.1 (UWP)
Profile104 .NETFramework 4.5 portable-net45+sl4+win8+wp75
Silverlight 4.0
Windows 8.0
WindowsPhone 7.5
Profile111 .NETFramework 4.5 portable-net45+win8+wpa81 netstandard1.1
Windows 8.0
WindowsPhone 8.1 (UWP)
Profile136 .NETFramework 4.0 portable-net40+sl5+win8+wp8
Silverlight 5.0
Windows 8.0
WindowsPhone 8.0 (SL)
Profile143 .NETFramework 4.0.3 portable-net403+sl4+win8+wp8
Silverlight 4.0
Windows 8.0
WindowsPhone 8.0 (SL)
Profile147 .NETFramework 4.0.3 portable-net403+sl5+win8+wp8
Silverlight 5.0
Windows 8.0
WindowsPhone 8.0 (SL)
Profile151 NETFramework 4.5.1 portable-net451+win81+wpa81 netstandard1.2
Windows 8.1
WindowsPhone 8.1 (UWP)
Profile154 .NETFramework 4.5 portable-net45+sl4+win8+wp8
Silverlight 4.0
Windows 8.0
WindowsPhone 8.0 (SL)
Profile157 Windows 8.1 portable-win81+wp81+wpa81 netstandard1.0
WindowsPhone 8.1 (SL)
WindowsPhone 8.1 (UWP)
Profile158 .NETFramework 4.5 portable-net45+sl5+win8+wp8
Silverlight 5.0
Windows 8.0
WindowsPhone 8.0 (SL)
Profile225 .NETFramework 4.0 portable-net40+sl5+win8+wpa81
Silverlight 5.0
Windows 8.0
WindowsPhone 8.1 (UWP)
Profile240 .NETFramework 4.0.3 portable-net403+sl5+win8+wpa8
Silverlight 5.0
Windows 8.0
WindowsPhone 8.1 (UWP)
Profile255 .NETFramework 4.5 portable-net45+sl5+win8+wpa81
Silverlight 5.0
Windows 8.0
WindowsPhone 8.1 (UWP)
Profile259 .NETFramework 4.5 portable-net45+win8+wpa81+wp8 netstandard1.0
Windows 8.0
WindowsPhone 8.1 (UWP)
WindowsPhone 8.0 (SL)
Profile328 .NETFramework 4.0 portable-net40+sl5+win8+wpa81+wp8
Silverlight 5.0
Windows 8.0
WindowsPhone 8.1 (UWP)
WindowsPhone 8.0 (SL)
Profile336 .NETFramework 4.0.3 portable-net403+sl5+win8+wpa81+wp8
Silverlight 5.0
Windows 8.0
WindowsPhone 8.1 (UWP)
WindowsPhone 8.0 (SL)
Profile344 .NETFramework 4.5 portable-net45+sl5+win8+wpa81+wp8
Silverlight 5.0
Windows 8.0
WindowsPhone 8.1 (UWP)
WindowsPhone 8.0 (SL)

此外,面向 Xamarin 的 NuGet 包可以使用其他 Xamarin 定义的框架:

名称 说明 .NET Standard
monoandroid Mono 对 Android OS 的支持 netstandard1.4
monotouch 对 iOS 的 Mono 支持 netstandard1.4
monomac 对 OSX 的 Mono 支持 netstandard1.4
xamarinios 支持适用于 iOS 的 Xamarin netstandard1.4
xamarinmac 支持 Xamarin for Mac netstandard1.4
xamarinpsthree 对 Playstation 3 上的 Xamarin 的支持 netstandard1.4
xamarinpsfour 对 Playstation 4 上的 Xamarin 的支持 netstandard1.4
xamarinpsvita PS Vita 上的 Xamarin 支持 netstandard1.4
xamarinwatchos Xamarin for Watch OS netstandard1.4
xamarintvos 适用于电视 OS 的 Xamarin netstandard1.4
xamarinxboxthreesixty 适用于 XBox 360 的 Xamarin netstandard1.4
xamarinxboxone 适用于 XBox One 的 Xamarin netstandard1.4

注释

Stephen Cleary 创建了一个工具,其中列出了受支持的 PCL,可在 .NET 中的框架配置文件的帖子中找到该工具。