Skip to content

Commit 2fc2bf8

Browse files
committed
cleanup
1 parent 225a895 commit 2fc2bf8

1 file changed

Lines changed: 58 additions & 54 deletions

File tree

docs/consume-packages/Package-References-in-Project-Files.md

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -164,60 +164,6 @@ NuGet uses these moniker properties — not the `TargetFramework` string — for
164164

165165
For more details on the aliasing mechanism, see [TargetFramework values are aliases](../reference/target-frameworks.md#targetframework-values-are-aliases).
166166

167-
### Multi-targeting with duplicate frameworks
168-
169-
*This feature requires [NuGet 7.6](../release-notes/NuGet-7.6.md) / .NET SDK 10.0.300 or later.*
170-
171-
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.
176-
177-
```xml
178-
<Project Sdk="Microsoft.NET.Sdk">
179-
<PropertyGroup>
180-
<TargetFrameworks>apple;banana</TargetFrameworks>
181-
</PropertyGroup>
182-
183-
<PropertyGroup>
184-
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
185-
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
186-
<TargetFrameworkMoniker>.NETCoreApp,Version=v10.0</TargetFrameworkMoniker>
187-
</PropertyGroup>
188-
</Project>
189-
```
190-
191-
- **Multi-version extensions**: Target multiple versions of a host application, such as Visual Studio.
192-
193-
```xml
194-
<Project Sdk="Microsoft.VisualStudio.Extensibility.Sdk">
195-
<PropertyGroup>
196-
<TargetFrameworks>vs18;vs17.14</TargetFrameworks>
197-
</PropertyGroup>
198-
</Project>
199-
```
200-
201-
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-
221167
## Adding a PackageReference condition
222168

223169
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.
@@ -408,6 +354,8 @@ In order to persist the full closure of package dependencies, you can opt-in to
408354

409355
If this property is set, NuGet restore will generate a lock file (`packages.lock.json`) at the project root directory that lists all the package dependencies.
410356

357+
The `packages.lock.json` has a versioned format. Depending on the features you have enabled, such as Central Package Management and transitive pinning, or whether you use a duplicate effective target framework you may get a different version.
358+
411359
> [!Note]
412360
> Once a project has `packages.lock.json` file in its root directory, the lock file is always used with restore even if the property `RestorePackagesWithLockFile` is not set. So another way to opt-in to this feature is to create a dummy blank `packages.lock.json` file in the project's root directory.
413361
@@ -547,6 +495,62 @@ You can leave off `$(AssetTargetFallback)` if you wish to overwrite, instead of
547495
>
548496
> `$(PackageTargetFallback)` was an earlier feature that attempted to address this challenge, but it is fundamentally broken and *should* not be used. To migrate from `$(PackageTargetFallback)` to `$(AssetTargetFallback)`, simply change the property name.
549497
498+
### Multi-targeting with duplicate frameworks
499+
500+
*This feature requires [NuGet 7.6](../release-notes/NuGet-7.6.md) / .NET SDK 10.0.300 or later.*
501+
502+
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.
503+
504+
This enables use cases such as:
505+
506+
- **Multi-RID builds**: Build platform-specific assemblies from a single project.
507+
508+
```xml
509+
<Project Sdk="Microsoft.NET.Sdk">
510+
<PropertyGroup>
511+
<TargetFrameworks>net10.0;linux;ios</TargetFrameworks>
512+
</PropertyGroup>
513+
514+
<PropertyGroup Condition="'$(TargetFramework)' == 'linux' OR '$(TargetFramework)' == 'ios' OR '$(TargetFramework)' == 'net10.0'">
515+
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
516+
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
517+
<TargetFrameworkMoniker>.NETCoreApp,Version=v10.0</TargetFrameworkMoniker>
518+
</PropertyGroup>
519+
</Project>
520+
```
521+
522+
- **Benchmarking different versions of a package**
523+
524+
```xml
525+
<Project Sdk="Microsoft.NET.Sdk">
526+
<PropertyGroup>
527+
<TargetFrameworks>benchmark7.0;benchmark8.0</TargetFrameworks>
528+
</PropertyGroup>
529+
530+
<!-- Frameworks ommited for brevity-->
531+
532+
<ItemGroup>
533+
<PackageReference Include="BenchmarkDotNet" Version="0.13.9" />
534+
<PackageReference Include="Contoso.FastLibrary" Version="7.0" Condition="'$(TargetFramework)' == 'benchmark7.0' "/>
535+
<PackageReference Include="Contoso.FastLibrary" Version="8.0" Condition="'$(TargetFramework)' == 'benchmark8.0' "/>
536+
</ItemGroup>
537+
</Project>
538+
```
539+
540+
#### Pack
541+
542+
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.
543+
544+
#### Project references
545+
546+
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.
547+
548+
#### Limitations
549+
550+
- Only SDK-style projects support duplicate effective frameworks.
551+
- Aliases that contain path separator characters (`/` or `\`) are blocked.
552+
- 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.
553+
550554
## PrunePackageReference
551555

552556
The .NET Runtime is constantly evolving, with performance improvements and new APIs each release.

0 commit comments

Comments
 (0)