NuGet 在多個地方使用目標框架參考,專門識別並隔離套件中依賴框架的元件:
- 專案檔案:對於 SDK 風格的專案, .csproj 包含目標框架參考。
- .nuspec manifest:套件可根據專案的目標框架,指示專案中需包含的不同套件。
-
.nupkg 資料夾名稱:套件資料夾中的
lib資料夾可依目標框架命名,每個資料夾包含該框架所需的 DLL 及其他內容。 -
packages.config:
targetframework依賴屬性指定要安裝的套件變體。
關於所有支援的目標框架及其 TFM 語法的標準列表,請參見 SDK 風格專案中的目標框架。
TargetFramework 的值是別名
TargetFramework專案檔案中的屬性是一個友善名稱——一個別名——會被轉換成標準框架身份。 .NET SDK 透過設定 TargetFrameworkMoniker (TFM),以及在適用時設定 TargetPlatformMoniker 屬性來執行此轉換。
例如,當你寫入 <TargetFramework>net10.0-windows</TargetFramework>時,.NET SDK 會將其轉換成:
TargetFrameworkMoniker=.NETCoreApp,Version=v10.0TargetPlatformMoniker=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>
這個專案會還原並編譯 .NET 10.0,儘管它的 TargetFramework 值是 banana。 .NET SDK 已經依賴這種別名機制來處理作業系統專屬的 TFM,例如 net8.0-iosnet8.0-android和 ,其中短 TFM 會轉換成完整名稱並附上平台資訊。
多目標與重複框架
從 NuGet 7.6 / .NET SDK 10.0.300 開始,多個 TargetFrameworks 別名可以解析成同一個有效的框架。 這使得像多RID建置和多版本擴充目標鎖定等情境成為可能。 關於如何處理還原、打包、鎖定檔案及專案參考的細節,請參見 「針對多個框架」。
支援的架構
框架通常以短期目標框架名稱(short target framework nameer,簡稱 TFM)來指稱。 在 .NET Standard 中,這也被推廣到 TxM ,允許單一參考多個框架。
NuGet 用戶端支援下表中的框架。 等價物以括號內標示。 請注意,有些工具, dotnet例如,可能會在某些檔案中使用標準 TFM 的變體。 例如,在檔案中使用.NETCoreApp2.0.nuspec,dotnet pack而非 netcoreapp2.0。 各種 NuGet 用戶端工具都能妥善處理這些變化,但直接編輯檔案時,應該始終使用標準 TFM。
| 名稱 | 縮寫 | TFMs/TxMs |
|---|---|---|
| .NET Framework | 網 | net11 |
| net20 | ||
| net35 | ||
| net40 | ||
| net403 | ||
| net45 | ||
| net451 | ||
| net452 | ||
| net46 | ||
| net461 | ||
| net462 | ||
| net47 | ||
| net471 | ||
| net472 | ||
| net48 | ||
| Microsoft Store(Windows 商店) | 網路核心 | 網路核心 [netcore45] |
| Netcore45 [Win,Win8] | ||
| .NET Core 451 [win81] | ||
| netcore50 | ||
| .NET 微框架 | 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.XXXX(其中 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 Core) | netcoreapp | netcoreapp1.0 |
| netcoreapp1.1 | ||
| netcoreapp2.0 | ||
| netcoreapp2.1 | ||
| netcoreapp2.2 | ||
| netcoreapp3.0 | ||
| netcoreapp3.1 | ||
| 網 | Net5.0 | |
| .NET 6.0 | ||
| Net7.0 | ||
| net8.0 | ||
| net9.0 | ||
| net10.0 | ||
| Tizen | 提岑 | tizen3 |
| tizen4 | ||
| Native | 原生 | 原生 |
已棄用框架
以下框架已被棄用。 針對這些框架的套件應遷移到指定的替代方案。
| 已棄用框架 | 替換 |
|---|---|
| aspnet50 | netcoreapp |
| aspnetcore50 | |
| dnxcore50 | |
| dnx | |
| dnx45 | |
| dnx451 | |
| dnx452 | |
| dotnet | netstandard |
| dotnet50 | |
| dotnet51 | |
| dotnet52 | |
| dotnet53 | |
| dotnet54 | |
| dotnet55 | |
| dotnet56 | |
| winrt | 贏得 |
優先權
有許多框架彼此相關且相容,但不一定等同:
| Framework | 可使用 |
|---|---|
| uap(通用 Windows 平台) | Windows 8.1 |
| wpa81 | |
| netcore50 | |
| win(Microsoft 商店) | winrt |
NET 標準
.NET Standard 簡化了二進位相容框架間的引用,允許單一目標框架參考多個框架的組合。 (背景請參見 .NET 入門書。)
NuGet 最近框架工具模擬 NuGet 用來從多個可用框架資產中選擇一個框架的過程,該工具基於專案框架。
dotnet這一系列名稱應用於 NuGet 3.3 及更早版本;netstandard該名稱語法應用於 v3.4 及以後版本。
可攜式類別函式庫
警告
不建議做PCL。 雖然支援 PCL,但套件作者應該支援 netstandard。 .NET 平台標準是 PCL 的演進版本,代表跨平台的二進位可攜性,使用單一名稱,不綁定於像 portable-a+b+c 名稱那樣的靜態函式庫。
為了定義指向多個子目標框架的目標框架, portable 關鍵字使用時會用來在參考框架列表前置。 避免人為加入非直接編譯的額外框架,因為這可能導致這些框架產生意想不到的副作用。
第三方定義的額外框架則能與其他以此類方式存取的環境相容。 此外,也有簡寫型數可用來參考這些相關框架組合,但 Profile#這不建議使用這些數字,因為這會降低資料夾和 .nuspec的可讀性。
| 簡介# | 框架 | 完整名稱 | .NET Standard |
|---|---|---|---|
| Profile2 | .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 | |
| 銀光 5.0 | |||
| Profile18 | .NETFramework 4.0.3 | Portable-Net403+SL4 | |
| Silverlight 4.0 | |||
| 檔案19 | .NETFramework 4.0.3 | Portable-Net403+SL5 | |
| 銀光 5.0 | |||
| Profile23 | .NETFramework 4.5 | Portable-Net45+SL4 | |
| Silverlight 4.0 | |||
| Profile24 | .NETFramework 4.5 | 可攜式網路45+SL5 | |
| 銀光 5.0 | |||
| 檔案31 | Windows 8.1 | 可攜式-Win81+WP81 | netstandard1.0 |
| WindowsPhone 8.1 (SL) | |||
| 檔案32 | Windows 8.1 | 可攜式 Win81+WPA81 | netstandard1.2 |
| WindowsPhone 8.1(UWP) | |||
| 檔案36 | .NETFramework 4.0 | Portable-Net40+SL4+Win8+WP8 | |
| Silverlight 4.0 | |||
| Windows 8.0 | |||
| WindowsPhone 8.0 (SL) | |||
| 檔案37 | .NETFramework 4.0 | Portable-Net40+SL5+Win8 | |
| 銀光 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 | |
| 銀光 5.0 | |||
| Windows 8.0 | |||
| Profile44 | .NETFramework 4.5.1 | Portable-Net451+Win81 | netstandard1.2 |
| Windows 8.1 | |||
| 檔案46 | .NETFramework 4.5 | Portable-Net45+SL4+Win8 | |
| Silverlight 4.0 | |||
| Windows 8.0 | |||
| Profile47 | .NETFramework 4.5 | Portable-Net45+SL5+Win8 | |
| 銀光 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 | 可攜式-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 | |
| 銀光 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) | |||
| 檔案147 | .NETFramework 4.0.3 | Portable-Net403+SL5+Win8+WP8 | |
| 銀光 5.0 | |||
| Windows 8.0 | |||
| WindowsPhone 8.0 (SL) | |||
| 檔案151 | NETFramework 4.5.1 | Portable-Net451+Win81+WPA81 | netstandard1.2 |
| Windows 8.1 | |||
| WindowsPhone 8.1(UWP) | |||
| 檔案154 | .NETFramework 4.5 | Portable-Net45+SL4+Win8+WP8 | |
| Silverlight 4.0 | |||
| Windows 8.0 | |||
| WindowsPhone 8.0 (SL) | |||
| Profile157 | Windows 8.1 | 可攜式 Win81+WP81+WPA81 | netstandard1.0 |
| WindowsPhone 8.1 (SL) | |||
| WindowsPhone 8.1(UWP) | |||
| Profile158 | .NETFramework 4.5 | Portable-Net45+SL5+Win8+WP8 | |
| 銀光 5.0 | |||
| Windows 8.0 | |||
| WindowsPhone 8.0 (SL) | |||
| 檔案225 | .NETFramework 4.0 | Portable-Net40+SL5+Win8+WPA81 | |
| 銀光 5.0 | |||
| Windows 8.0 | |||
| WindowsPhone 8.1(UWP) | |||
| Profile240 | .NETFramework 4.0.3 | Portable-Net403+SL5+Win8+WPA8 | |
| 銀光 5.0 | |||
| Windows 8.0 | |||
| WindowsPhone 8.1(UWP) | |||
| 檔案255 | .NETFramework 4.5 | Portable-Net45+SL5+Win8+WPA81 | |
| 銀光 5.0 | |||
| Windows 8.0 | |||
| WindowsPhone 8.1(UWP) | |||
| 檔案259 | .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 | |
| 銀光 5.0 | |||
| Windows 8.0 | |||
| WindowsPhone 8.1(UWP) | |||
| WindowsPhone 8.0 (SL) | |||
| Profile336 | .NETFramework 4.0.3 | Portable-Net403+SL5+Win8+WPA81+WP8 | |
| 銀光 5.0 | |||
| Windows 8.0 | |||
| WindowsPhone 8.1(UWP) | |||
| WindowsPhone 8.0 (SL) | |||
| Profile344 | .NETFramework 4.5 | Portable-Net45+SL5+Win8+WPA81+WP8 | |
| 銀光 5.0 | |||
| Windows 8.0 | |||
| WindowsPhone 8.1(UWP) | |||
| WindowsPhone 8.0 (SL) |
此外,針對 Xamarin 的 NuGet 套件可使用更多 Xamarin 定義的框架:
| 名稱 | 說明 | .NET Standard |
|---|---|---|
| 單安卓 | Android 作業系統的 Mono 支援 | netstandard1.4 |
| 單點觸控 | iOS 的 Mono 支援 | netstandard1.4 |
| Monomac | OSX 的單聲道支援 | netstandard1.4 |
| 薩馬里尼奧斯 | 支援 iOS 版 Xamarin。 | netstandard1.4 |
| 薩馬林馬克 | Xamarin(Mac版)的支援 | netstandard1.4 |
| Xamarinpsthree | PlayStation 3 上支援 Xamarin。 | netstandard1.4 |
| Xamarinpsfour | 支援 Xamarin 在 PlayStation 4 上 | netstandard1.4 |
| Xamarinpsvita | PS Vita 上對 Xamarin的支援 | netstandard1.4 |
| Xamarin watchOS | Xamarin(手錶作業系統版) | netstandard1.4 |
| xamarintvos | Xamarin 用於 TV 作業系統 | netstandard1.4 |
| XamarinXboxThreesixty | Xamarin:適用於 XBox 360 | netstandard1.4 |
| Xamarinxboxone | Xamarin:XBox One 版本 | netstandard1.4 |
備註
Stephen Cleary 創建了一個工具,列出支援的 PCL,你可以在他的文章《 Framework profiles in .NET》中找到。