Skip to content

Commit 70547bf

Browse files
authored
Update nuget.config examples & unemphasize NuGetDefaults.Config (#3290)
1 parent 93b8700 commit 70547bf

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

docs/consume-packages/configuring-nuget-behavior.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.topic: conceptual
99

1010
# Common NuGet configurations
1111

12-
NuGet's behavior is driven by the accumulated settings in one or more `NuGet.Config` (XML) files that can exist at solution- (project if no solution is used), user-, and computer-wide levels. A global `NuGetDefaults.Config` file also specifically configures package sources. Settings apply to all commands issued in the CLI, the Package Manager Console, and the Package Manager UI.
12+
NuGet's behavior is driven by the accumulated settings in one or more config (XML) files that can exist at solution- (project if no solution is used), user-, and computer-wide levels.
1313

1414
## Config file locations and uses
1515

@@ -58,29 +58,35 @@ Settings are managed using the NuGet CLI [config command](../reference/cli-refer
5858
Windows:
5959

6060
```cli
61-
# Set repositoryPath in the user-level config file
62-
nuget config -set repositoryPath=c:\packages
61+
# Set globalPackagesFolder in the user-level config file
62+
dotnet nuget config set globalPackagesFolder "C:\packages"
63+
64+
# Set repositoryPath (available for packages.config only) in the user-level config file
65+
dotnet nuget config set repositoryPath "C:\packages"
6366
6467
# Set repositoryPath in solution-level files
65-
nuget config -set repositoryPath=c:\packages -configfile c:\my.Config
66-
nuget config -set repositoryPath=c:\packages -configfile .\myApp\NuGet.Config
68+
dotnet nuget config set repositoryPath "C:\packages" --configfile "C:\my.config"
69+
dotnet nuget config set repositoryPath "c:\packages" --configfile "..\..\my.config"
6770
6871
# Set repositoryPath in the computer-level file (requires elevation)
69-
nuget config -set repositoryPath=c:\packages -configfile %ProgramFiles(x86)%\NuGet\Config\NuGet.Config
72+
dotnet nuget config set repositoryPath "c:\packages" --configfile "%appdata%\NuGet\NuGet.Config"
7073
```
7174

7275
Mac/Linux:
7376

7477
```cli
75-
# Set repositoryPath in the user-level config file
76-
nuget config -set repositoryPath=/home/packages
78+
# Set globalPackagesFolder in the user-level config file
79+
dotnet nuget config set globalPackagesFolder /home/packages
80+
81+
# Set repositoryPath (available for packages.config only) in the user-level config file
82+
dotnet nuget config set repositoryPath /home/packages
7783
7884
# Set repositoryPath in solution-level files
79-
nuget config -set repositoryPath=/home/projects/packages -configfile /home/my.Config
80-
nuget config -set repositoryPath=/home/packages -configfile home/myApp/NuGet.Config
85+
dotnet nuget config set repositoryPath /home/projects/packages --configfile /home/my.Config
86+
dotnet nuget config set repositoryPath /home/packages --configfile home/myApp/NuGet.Config
8187
8288
# Set repositoryPath in the computer-level file (requires elevation)
83-
nuget config -set repositoryPath=/home/packages -configfile $XDG_DATA_HOME/NuGet.Config
89+
dotnet nuget config set repositoryPath /home/packages --configfile $XDG_DATA_HOME/NuGet.Config
8490
```
8591

8692
> [!Note]
@@ -100,7 +106,10 @@ nuget config -set repositoryPath= -configfile /home/my.Config
100106

101107
### Creating a new config file
102108

103-
Copy the template below into the new file and then use `nuget config -configFile <filename>` to set values:
109+
Using the .NET CLI, create a default nuget.config by running `dotnet new nugetconfig`.
110+
For more information, see [dotnet CLI commands](../reference/dotnet-commands.md#package-consumption).
111+
112+
Alternatively, manually copy the template below into the new file and then use `nuget config -configFile <filename>` to set values:
104113

105114
```xml
106115
<?xml version="1.0" encoding="utf-8"?>
@@ -116,7 +125,7 @@ If a command line tool is used on a project file, rather than a solution file, t
116125

117126
Specifically, when a config file is not specified explicitly on the command line, NuGet loads settings from the different config files in the following order:
118127

119-
1. The [`NuGetDefaults.Config` file](#nuget-defaults-file), which contains settings related only to package sources.
128+
1. (*Uncommon*) The [`NuGetDefaults.Config` file](#nuget-defaults-file), which contains settings related only to package sources.
120129
1. The computer-level file.
121130
1. The user-level file.
122131
1. Files found in every folder in the path from the drive root to the current folder (where `nuget.exe` is invoked or the folder containing the Visual Studio solution). For example, if a command is invoked in `c:\A\B\C`, NuGet looks for and loads config files in `c:\`, then `c:\A`, then `c:\A\B`, and finally `c:\A\B\C`.
@@ -154,9 +163,9 @@ File A. User-level file, (`%appdata%\NuGet\NuGet.Config` on Windows, `~/.config/
154163
```xml
155164
<?xml version="1.0" encoding="utf-8"?>
156165
<configuration>
157-
<activePackageSource>
158-
<add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
159-
</activePackageSource>
166+
<packageSources>
167+
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
168+
</packageSources>
160169
</configuration>
161170
```
162171

@@ -226,7 +235,9 @@ These files cannot be edited by the standard tooling.
226235

227236
## NuGet defaults file
228237

229-
The `NuGetDefaults.Config` file exists to specify package sources from which packages are installed and updated, and to control the default target for publishing packages with `nuget push`. Because administrators can conveniently (using Group Policy, for example) deploy consistent `NuGetDefaults.Config` files to developer and build machines, they can ensure that everyone in the organization is using the correct package sources rather than nuget.org.
238+
The `NuGetDefaults.Config` is uncommon and can only specify package sources from which packages are installed and updated, or control the default target for publishing packages with `nuget push`.
239+
240+
Because administrators can conveniently (using Group Policy, for example) deploy consistent `NuGetDefaults.Config` files to developer and build machines, they can ensure that everyone in the organization is using consistent package sources, whether or not that includes nuget.org.
230241

231242
> [!Important]
232243
> The `NuGetDefaults.Config` file never causes a package source to be removed from a developer's NuGet configuration. That means if the developer has already used NuGet and therefore has the nuget.org package source registered, it won't be removed after the creation of a `NuGetDefaults.Config` file.

0 commit comments

Comments
 (0)