You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/consume-packages/Package-References-in-Project-Files.md
+76-54Lines changed: 76 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -142,6 +142,82 @@ Note that because `build` is not included with `PrivateAssets`, targets and prop
142
142
> [!NOTE]
143
143
> When `developmentDependency` is set to `true` in a `.nuspec` file, this marks a package as a development-only dependency, which prevents the package from being included as a dependency in other packages. With PackageReference *(NuGet 4.8+)*, this flag also means that it will exclude compile-time assets from compilation. For more information, see [DevelopmentDependency support for PackageReference](https://github.com/NuGet/Home/wiki/DevelopmentDependency-support-for-PackageReference).
144
144
145
+
## Targeting multiple frameworks
146
+
147
+
SDK-style projects support multi-targeting by listing multiple values in the `TargetFrameworks` property. When a project targets multiple frameworks, NuGet restore produces a separate dependency graph for each framework, and `dotnet pack` creates a package with framework-specific assets for each target.
For a step-by-step guide on setting up a multi-targeted project, see [Support multiple .NET frameworks in your project file](../create-packages/multiple-target-frameworks-project-file.md).
158
+
159
+
### How TargetFramework values work
160
+
161
+
The `TargetFramework` property in a project file is a friendly name — an alias — that gets translated into a canonical framework identity. The .NET SDK performs this translation by setting the `TargetFrameworkMoniker` (TFM), and when applicable, the `TargetPlatformMoniker` properties.
162
+
163
+
NuGet uses these moniker properties — not the `TargetFramework` string — for package compatibility checks. This means the `TargetFramework` value itself can be any string, as long as the moniker properties are set correctly.
164
+
165
+
For more details on the aliasing mechanism, see [TargetFramework values are aliases](../reference/target-frameworks.md#targetframework-values-are-aliases).
Because `TargetFramework` values are aliases, multiple aliases can resolve to the *same* effective framework. Starting with [NuGet 7.6](../release-notes/NuGet-7.6.md) / .NET SDK 10.0.300, NuGet and the .NET SDK support this scenario.
172
+
173
+
This enables use cases such as:
174
+
175
+
-**Multi-RID builds**: Build platform-specific assemblies from a single project.
In this example, the Visual Studio Extensibility SDK is responsible for setting the canonical moniker properties for each alias.
202
+
203
+
#### Pack
204
+
205
+
A NuGet package can only contain one set of build output and one dependency group per effective framework. When you pack a project with duplicate effective frameworks, you must tell NuGet which alias contributes these assets or the pack raises [NU5051](../reference/errors-and-warnings/NU5051.md). See [NU5051](../reference/errors-and-warnings/NU5051.md) for resolution steps and examples.
206
+
207
+
#### Lock file
208
+
209
+
When a project uses duplicate effective frameworks, the [packages lock file](#locking-dependencies) is automatically upgraded to a format that uses the alias as the key instead of the effective framework. This upgrade happens transparently — locked mode and CI/CD scenarios continue to work as before.
210
+
211
+
#### Project references
212
+
213
+
When a project references another project that has multiple aliases resolving to the same framework, NuGet uses the alias name as a tiebreaker. If the referencing project has an alias with the same name as one in the referenced project, that alias is preferred. If there’s no matching name and multiple candidates exist, NuGet reports an error.
214
+
215
+
#### Limitations
216
+
217
+
- Only SDK-style projects support duplicate effective frameworks.
218
+
- Aliases that contain path separator characters (`/` or `\`) are blocked.
219
+
- Visual Studio’s Package Manager UI doesn’t have special support for duplicate frameworks, but you can manage packages by editing the project file directly or using the `dotnet` CLI.
220
+
145
221
## Adding a PackageReference condition
146
222
147
223
You can use a condition to control whether a package is included. Conditions can use any MSBuild variable or a variable defined in the targets or props file. However, at present, only the `TargetFramework` variable is supported.
SDK-style projects support [multi-targeting](../create-packages/multiple-target-frameworks-project-file.md) by listing multiple values in the `TargetFrameworks` property. Because [TargetFramework values are aliases](../reference/target-frameworks.md#targetframework-values-are-aliases), multiple aliases can resolve to the *same* effective framework. Starting with [NuGet 7.6](../release-notes/NuGet-7.6.md) / .NET SDK 10.0.300, NuGet and the .NET SDK support this scenario.
247
-
248
-
This enables use cases such as:
249
-
250
-
-**Multi-RID builds**: Build platform-specific assemblies from a single project.
In this example, the Visual Studio Extensibility SDK is responsible for setting the canonical moniker properties for each alias.
277
-
278
-
### Pack
279
-
280
-
A NuGet package can only contain one set of build output and one dependency group per effective framework. When you pack a project with duplicate effective frameworks, you must tell NuGet which alias contributes these assets or the pack raises [NU5051](../reference/errors-and-warnings/NU5051.md). See [NU5051](../reference/errors-and-warnings/NU5051.md) for resolution steps and examples.
281
-
282
-
### Lock file
283
-
284
-
When a project uses duplicate effective frameworks, the [packages lock file](#locking-dependencies) is automatically upgraded to a format that uses the alias as the key instead of the effective framework. This upgrade happens transparently — locked mode and CI/CD scenarios continue to work as before.
285
-
286
-
### Project references
287
-
288
-
When a project references another project that has multiple aliases resolving to the same framework, NuGet uses the alias name as a tiebreaker. If the referencing project has an alias with the same name as one in the referenced project, that alias is preferred. If there's no matching name and multiple candidates exist, NuGet reports an error.
289
-
290
-
### Limitations
291
-
292
-
- Only SDK-style projects support duplicate effective frameworks.
293
-
- Aliases that contain path separator characters (`/` or `\`) are blocked.
294
-
- Visual Studio's Package Manager UI doesn't have special support for duplicate frameworks, but you can manage packages by editing the project file directly or using the `dotnet` CLI.
295
-
296
318
## NuGet warnings and errors
297
319
298
320
*This feature is available with NuGet **4.3** or above and with Visual Studio 2017 **15.3** or above.*
Copy file name to clipboardExpand all lines: docs/create-packages/multiple-target-frameworks-project-file.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,7 +70,7 @@ Here is the *.csproj* file that is generated using the preceding steps and .NET
70
70
71
71
Starting with [NuGet 7.6](../release-notes/NuGet-7.6.md) / .NET SDK 10.0.300, you can use multiple `TargetFrameworks` values that resolve to the same underlying framework. This enables scenarios like building for multiple runtimes or targeting multiple versions of a host application from a single project.
72
72
73
-
For details on how this works with restore and pack, see [Multi-targeting with duplicate frameworks](../consume-packages/package-references-in-project-files.md#multi-targeting-with-duplicate-frameworks).
73
+
For details on how this works with restore and pack, see [Targeting multiple frameworks](../consume-packages/package-references-in-project-files.md#multi-targeting-with-duplicate-frameworks).
Copy file name to clipboardExpand all lines: docs/reference/errors-and-warnings/NU5051.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,4 +98,4 @@ Suppress the default build output and dependencies for the secondary aliases, an
98
98
99
99
With this configuration, `net10.0` contributes the default `lib/net10.0/` build output and dependencies, while `linux` and `ios` place their assemblies under `runtimes/linux/lib/net10.0/` and `runtimes/ios/lib/net10.0/` respectively.
100
100
101
-
For more information about multi-targeting with duplicate frameworks, see [PackageReference in project files](../../consume-packages/package-references-in-project-files.md#multi-targeting-with-duplicate-frameworks). For more information about pack extensibility, see [pack target](../msbuild-targets.md#pack-target).
101
+
For more information about multi-targeting with duplicate frameworks, see [Targeting multiple frameworks](../../consume-packages/package-references-in-project-files.md#multi-targeting-with-duplicate-frameworks). For more information about pack extensibility, see [pack target](../msbuild-targets.md#pack-target).
Copy file name to clipboardExpand all lines: docs/reference/target-frameworks.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ This project restores and builds for .NET 10.0, even though the `TargetFramework
47
47
48
48
## Multi-targeting with duplicate frameworks
49
49
50
-
Starting with [NuGet 7.6](../release-notes/NuGet-7.6.md) / .NET SDK 10.0.300, multiple `TargetFrameworks` aliases can resolve to the same effective framework. This enables scenarios like multi-RID builds and multi-version extension targeting. For details on how this works with restore, pack, lock files, and project references, see [Multi-targeting with duplicate frameworks](../consume-packages/package-references-in-project-files.md#multi-targeting-with-duplicate-frameworks).
50
+
Starting with [NuGet 7.6](../release-notes/NuGet-7.6.md) / .NET SDK 10.0.300, multiple `TargetFrameworks` aliases can resolve to the same effective framework. This enables scenarios like multi-RID builds and multi-version extension targeting. For details on how this works with restore, pack, lock files, and project references, see [Targeting multiple frameworks](../consume-packages/package-references-in-project-files.md#multi-targeting-with-duplicate-frameworks).
0 commit comments