Skip to content

Commit 01de956

Browse files
authored
Merge pull request #3392 from NuGet/main
Public main to live
2 parents f4a942e + f204fb6 commit 01de956

File tree

8 files changed

+69
-4
lines changed

8 files changed

+69
-4
lines changed
33 KB
Loading

docs/archive/project-json-and-uwp.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ ms.topic: conceptual
1010
# project.json and UWP
1111

1212
> [!Important]
13-
> This content is deprecated. Projects should use either the `packages.config` or PackageReference formats.
13+
> This content is deprecated. Projects should use the PackageReference formats.
14+
> Learn how to [migrate your project.json project to PackageReference](./project-json.md#migrate-projectjson-to-packagereference).
1415
1516
This document describes the package structure that employs features in NuGet 3+ (Visual Studio 2015 and later). The `minClientVersion` property of your `.nuspec` can be used to state that you require the features described here by setting it to 3.1.
1617

docs/archive/project-json-impact.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ ms.topic: conceptual
1010
# Impact of project.json when creating packages
1111

1212
> [!Important]
13-
> This content is deprecated. Projects should use either the `packages.config` or PackageReference formats.
13+
> This content is deprecated. Projects should use the PackageReference formats.
14+
> Learn how to [migrate your project.json project to PackageReference](./project-json.md#migrate-projectjson-to-packagereference).
1415
1516
The `project.json` system used in NuGet 3+ affects package authors in several ways as described in the following sections.
1617

docs/archive/project-json.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ ms.topic: reference
1010
# project.json reference
1111

1212
> [!Important]
13-
> This content is deprecated. Projects should use either the `packages.config` or PackageReference formats.
13+
> This content is deprecated. Projects should use the PackageReference formats.
14+
> Learn how to [migrate your project.json project to PackageReference](#migrate-projectjson-to-packagereference).
1415
15-
*NuGet 3.x+*
16+
*NuGet 3.x*
1617

1718
The `project.json` file maintains a list of packages used in a project, known as a package management format. It supersedes `packages.config` but is in turn superseded by [PackageReference](../consume-packages/package-references-in-project-files.md) with NuGet 4.0+.
1819

@@ -37,6 +38,18 @@ The [`project.lock.json`](#projectlockjson) file (described below) is also used
3738
}
3839
```
3940

41+
## Migrate project.json to PackageReference
42+
43+
The migration between project.json and PackageReference is straightforward. The easiest way to do it to use the built-in migrator in the latest Visual Studio 2022, Update 14.
44+
45+
1. Load the project.json project in Visual Studio.
46+
1. Go to the solution explorer of the project.json project and find the dependencies node.
47+
1. Click `Migrate project.json to PackageReference...`!
48+
49+
![Migrating from project.json to PackageReference](media/project-json-migrator.png)
50+
51+
Alternatively, you may use the [dotnet migrate](/dotnet/core/tools/dotnet-migrate), or do the migration manually by taking all of the content from the project.json file and replacing it with the equivalent [PackageReference syntax](../consume-packages/Package-References-in-Project-Files.md).
52+
4053
## Dependencies
4154

4255
Lists the NuGet package dependencies of your project in the following form:

docs/concepts/Dependency-Resolution.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ When using a floating version, NuGet resolves the highest version of a package t
6363
| 1.1.* | 1.1.0 <br> 1.1.1 <br> 1.1.2-alpha <br> 1.2.0-alpha | 1.1.1 | The highest stable version that respects the specified pattern.|
6464
| \*-\* | 1.1.0 <br> 1.1.1 <br> 1.1.2-alpha <br> 1.3.0-beta | 1.3.0-beta | The highest version including the not stable versions. | Available in Visual Studio version 16.6, NuGet version 5.6, .NET Core SDK version 3.1.300 |
6565
| 1.1.\*-\* | 1.1.0 <br> 1.1.1 <br> 1.1.2-alpha <br> 1.1.2-beta <br> 1.3.0-beta | 1.1.2-beta | The highest version respecting the pattern and including the not stable versions. | Available in Visual Studio version 16.6, NuGet version 5.6, .NET Core SDK version 3.1.300 |
66+
| 1.2.0-rc.* | 1.1.0 <br> 1.2.0-rc.1 <br> 1.2.0-rc.2 <br> 1.2.0 | 1.2.0 | Despite this being a version range with a prerelease part, stables are allowed if they match the stable part. Given that 1.2.0 > 1.2.0-rc.2, it is chosen. | |
6667

6768
> [!Note]
6869
> Floating version resolution does not take into account whether or not a package is listed.

docs/consume-packages/Central-Package-Management.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ Central package management applies to all `<PackageReference>`-based MSBuild pro
3838
To get started with central package management, you must create a `Directory.Packages.props` file at the root of your repository and set the MSBuild property
3939
`ManagePackageVersionsCentrally` to `true`.
4040

41+
You can create it manually or you can use the dotnet CLI:
42+
``` shell
43+
dotnet new packagesprops
44+
```
45+
4146
Inside, you then define each of the respective package versions required of your projects using `<PackageVersion />` elements that define the package ID and
4247
version.
4348

@@ -117,6 +122,7 @@ For an idea of how central package management may look like, refer to our [sampl
117122

118123
You can automatically override a transitive package version even without an explicit top-level `<PackageReference />` by opting into a feature known as
119124
transitive pinning. This promotes a transitive dependency to a top-level dependency implicitly on your behalf when necessary.
125+
Note that downgrades are allowed when transitive pinning a package. If you attempt to pin a package to a lower version than the one requested by your dependencies, restore will raise a [NU1109](../reference/errors-and-warnings/NU1109.md) error.
120126

121127
You can enable this feature by setting the MSBuild property `CentralPackageTransitivePinningEnabled` to `true` in a project or in a `Directory.Packages.props`
122128
or `Directory.Build.props` import file:
@@ -127,6 +133,45 @@ or `Directory.Build.props` import file:
127133
</PropertyGroup>
128134
```
129135

136+
### Transitive pinning and pack
137+
138+
When a package is transitively pinned, your project uses a higher than the one requested by your dependencies.
139+
If you create a package from your project, in order to ensure that your package will work, NuGet will promote the transitively pinned dependencies to explicit dependencies in the nuspec.
140+
141+
In the following example, `PackageA 1.0.0` has a dependency on `PackageB 1.0.0`.
142+
143+
```xml
144+
<Project>
145+
<ItemGroup>
146+
<PackageVersion Include="PackageA" Version="1.0.0" />
147+
<PackageVersion Include="PackageB" Version="2.0.0" />
148+
</ItemGroup>
149+
</Project>
150+
```
151+
152+
```xml
153+
<Project Sdk="Microsoft.NET.Sdk">
154+
<PropertyGroup>
155+
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
156+
<TargetFramework>net6.0</TargetFramework>
157+
</PropertyGroup>
158+
<ItemGroup>
159+
<PackageReference Include="PackageA" />
160+
</ItemGroup>
161+
</Project>
162+
```
163+
164+
When you use the pack command to create a package, both packages will appear in the dependency group.
165+
166+
```xml
167+
<group targetFramework="net6.0">
168+
<dependency id="PackageA" version="6.12.1" exclude="Build,Analyzers" />
169+
<dependency id="PackageB" version="6.12.1" exclude="Build,Analyzers" />
170+
</group>
171+
```
172+
173+
Because of this, the use of transitive pinning should be carefully evaluated when authoring a library as it may lead to dependencies you did not expect.
174+
130175
## Overriding package versions
131176

132177
You can override an individual package version by using the `VersionOverride` property on a `<PackageReference />` item. This overrides any `<PackageVersion />`
@@ -176,6 +221,7 @@ If you'd like to disable central package management for any a particular project
176221
```
177222

178223
## Global Package References
224+
179225
> [!Note]
180226
> This feature is only available in Visual Studio 2022 17.4 or higher, .NET SDK 7.0.100.preview7 or higher, and NuGet 6.4 or higher.
181227

docs/hosting-packages/Overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ There are also several other NuGet hosting products such as [Azure Artifacts](ht
3939
- [ProGet](https://inedo.com/proget) from Inedo
4040
- [Sleet](https://github.com/emgarten/sleet), an open-source NuGet V3 static feed generator
4141
- [TeamCity](https://www.jetbrains.com/teamcity/) from JetBrains.
42+
- [RepoFlow](https://www.repoflow.io), a simple and easy-to-use package management platform.
4243

4344
Regardless of how packages are hosted, you access them by adding them to the list of available sources in `NuGet.Config`. This can be done in Visual Studio as described in [Package Sources](../consume-packages/install-use-packages-visual-studio.md#package-sources), or from the command line using [`nuget sources`](../reference/cli-reference/cli-ref-sources.md). The path to a source can be a local folder pathname, a network name, or a URL.

docs/reference/cli-reference/cli-ref-sources.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,7 @@ nuget sources Enable -Name "nuget.org"
107107
108108
nuget sources add -name foo.bar -source C:\NuGet\local -username foo -password bar -StorePasswordInClearText -configfile %AppData%\NuGet\my.config
109109
110+
nuget sources add -name MyAzureDevOpsSource -source "https://pkgs.dev.azure.com/yourorgname/yourprojectname/_packaging/yourfeedname/nuget/v3/index.json" -username ignored -password <Personal Access Token>
111+
110112
nuget sources Update -Name "nuget.org" -ProtocolVersion 3
111113
```

0 commit comments

Comments
 (0)