Skip to content

Commit

Permalink
Update nuget.config examples & unemphasize NuGetDefaults.Config (#3290)
Browse files Browse the repository at this point in the history
  • Loading branch information
donnie-msft authored Jul 15, 2024
1 parent 93b8700 commit 70547bf
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions docs/consume-packages/configuring-nuget-behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ms.topic: conceptual

# Common NuGet configurations

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.
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.

## Config file locations and uses

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

```cli
# Set repositoryPath in the user-level config file
nuget config -set repositoryPath=c:\packages
# Set globalPackagesFolder in the user-level config file
dotnet nuget config set globalPackagesFolder "C:\packages"
# Set repositoryPath (available for packages.config only) in the user-level config file
dotnet nuget config set repositoryPath "C:\packages"
# Set repositoryPath in solution-level files
nuget config -set repositoryPath=c:\packages -configfile c:\my.Config
nuget config -set repositoryPath=c:\packages -configfile .\myApp\NuGet.Config
dotnet nuget config set repositoryPath "C:\packages" --configfile "C:\my.config"
dotnet nuget config set repositoryPath "c:\packages" --configfile "..\..\my.config"
# Set repositoryPath in the computer-level file (requires elevation)
nuget config -set repositoryPath=c:\packages -configfile %ProgramFiles(x86)%\NuGet\Config\NuGet.Config
dotnet nuget config set repositoryPath "c:\packages" --configfile "%appdata%\NuGet\NuGet.Config"
```

Mac/Linux:

```cli
# Set repositoryPath in the user-level config file
nuget config -set repositoryPath=/home/packages
# Set globalPackagesFolder in the user-level config file
dotnet nuget config set globalPackagesFolder /home/packages
# Set repositoryPath (available for packages.config only) in the user-level config file
dotnet nuget config set repositoryPath /home/packages
# Set repositoryPath in solution-level files
nuget config -set repositoryPath=/home/projects/packages -configfile /home/my.Config
nuget config -set repositoryPath=/home/packages -configfile home/myApp/NuGet.Config
dotnet nuget config set repositoryPath /home/projects/packages --configfile /home/my.Config
dotnet nuget config set repositoryPath /home/packages --configfile home/myApp/NuGet.Config
# Set repositoryPath in the computer-level file (requires elevation)
nuget config -set repositoryPath=/home/packages -configfile $XDG_DATA_HOME/NuGet.Config
dotnet nuget config set repositoryPath /home/packages --configfile $XDG_DATA_HOME/NuGet.Config
```

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

### Creating a new config file

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

Alternatively, manually copy the template below into the new file and then use `nuget config -configFile <filename>` to set values:

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

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:

1. The [`NuGetDefaults.Config` file](#nuget-defaults-file), which contains settings related only to package sources.
1. (*Uncommon*) The [`NuGetDefaults.Config` file](#nuget-defaults-file), which contains settings related only to package sources.
1. The computer-level file.
1. The user-level file.
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`.
Expand Down Expand Up @@ -154,9 +163,9 @@ File A. User-level file, (`%appdata%\NuGet\NuGet.Config` on Windows, `~/.config/
```xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<activePackageSource>
<add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
</activePackageSource>
<packageSources>
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
```

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

## NuGet defaults file

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.
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`.

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.

> [!Important]
> 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.
Expand Down

0 comments on commit 70547bf

Please sign in to comment.