Skip to content
1 change: 1 addition & 0 deletions docs/TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
### [nuget.exe CLI](consume-packages/install-use-packages-nuget-cli.md)
### [Package Manager Console (PowerShell)](consume-packages/install-use-packages-powershell.md)
## Configure NuGet
### [Visual Studio options](consume-packages/nuget-visual-studio-options.md)
### Package restore options
#### [Restore packages](consume-packages/package-restore.md)
#### [Troubleshooting](consume-packages/package-restore-troubleshooting.md)
Expand Down
38 changes: 13 additions & 25 deletions docs/consume-packages/Package-Source-Mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ author: nkolev92
ms.author: nikolev
ms.date: 10/18/2023
ms.topic: conceptual
f1_keywords:
- "vs.toolsoptionspages.nuget_package_manager.package_source_mapping"
---

# Package Source Mapping
Expand All @@ -20,7 +18,7 @@ With Package Source Mapping, you can filter, per package, which source(s) NuGet
We also have suggestions for other [best practices](..\concepts\Security-Best-Practices.md) to help you fortify your supply chain against attacks.

Package Source Mapping was added in [NuGet 6.0](..\release-notes\NuGet-6.0.md).
Starting with Visual Studio 17.5, you can add and remove Package Source Mappings with the Visual Studio Options Dialog.
Starting with Visual Studio 17.5, you can add and remove Package Source Mappings with the Visual Studio Options Dialog. For detailed information on all Visual Studio NuGet options, see [NuGet Options in Visual Studio](nuget-visual-studio-options.md).

### Visual Studio support

Expand Down Expand Up @@ -55,34 +53,23 @@ To opt into this feature, you must have a `nuget.config` file. Having a single `

_From the Package Manager UI_

- Select a package from the list to show it in the Details Pane.
- Press the `Configure` button to open the Package Source Mappings options page.
* Select a package from the list to show it in the Details Pane.
* Press the `Configure` button to open the Package Source Mappings options page.

![The NuGet Package Manager window in Visual Studio showing a selected package, and a highlight around the "Package source mapping is off" status with a `Configure` button.](media/packageSourceMapping_PMUI_Status_Off_Annotated.png)

_From the Visual Studio Options Dialog_

- Go to the `Tools` menu in the main Visual Studio toolbar, and choose `NuGet Package Manager` -> `Package Manager Settings`.
- Navigate to the `Package Source Mappings` page.
* Go to the `Tools` menu in the main Visual Studio toolbar, and choose `NuGet Package Manager` -> `Package Manager Settings`.
* Navigate to the `Package Source Mappings` page.

![The Visual Studio `Package Source Mappings` Options Dialog showing no package source mappings, with an `Add` button to create a new mapping.](media/packageSourceMapping_VSOptions_NoMappings.png)
For details about managing NuGet package source mappings, see [NuGet Options in Visual Studio](nuget-visual-studio-options.md#package-source-mapping).

3. Press the `Add` button in the `Package Source Mappings` page to open the `Add Package Source Mappings` dialog.

![The `Add Package Source Mappings` dialog](media/packageSourceMapping_VSOptions_AddMappingOpened.png)
4. Enter a Package ID or Package Pattern, and select one or more package source(s) by toggling the checkbox for your desired source(s).

![The `Add Package Source Mappings` dialog with a filled package pattern and selected package source.](media/packageSourceMapping_VSOptions_AddMappingFilled.png)

5. The `Package Source Mapping` options page will show the newly created source mapping.

![The `Package Source Mapping` options page showing the newly created source mapping](media/packageSourceMapping_VSOptions_AddMappingCompleted.png)

6. Press `OK` on the Options Dialog to save changes to the applicable `nuget.config`.
7. The NuGet Package Manager window will refresh and reflect the new status of the selected package's source mappings.
The NuGet Package Manager window will refresh and reflect the new status of the selected package's source mappings.
![The NuGet Package Manager window in Visual Studio showing a selected package with the "Package source mapping found" status with a `Configure` button.](media/packageSourceMapping_PMUI_Status_Mapped.png)

### Enable by manually editing `nuget.config`

* Declare your desired package sources in your `nuget.config` file.
* Following your source declarations, add a `<packageSourceMapping>` element that specifies the desired mappings for each source.
* Declare exactly one `packageSource` element for each source in use.
Expand Down Expand Up @@ -124,9 +111,9 @@ For maximum flexibility and control, NuGet requires that all packages match a pa

### Package Pattern requirements

All requested packages must map to one or more sources by matching a defined package pattern. In other words, once you have defined a `packageSourceMapping` element you must explicitly define which sources *every* package - *including transitive packages* - will be restored from.
All requested packages must map to one or more sources by matching a defined package pattern. In other words, once you have defined a `packageSourceMapping` element you must explicitly define which sources _every_ package - _including transitive packages_ - will be restored from.

* Both top-level *and transitive* packages must match defined patterns. There is no requirement that a top level package and its dependencies come from the same source.
* Both top-level _and transitive_ packages must match defined patterns. There is no requirement that a top level package and its dependencies come from the same source.
* The same ID pattern can be defined on multiple sources, allowing matching package IDs to be restored from any of the feeds that define the pattern. However, this isn't recommended due to the impact on restore predictability (a given package could come from multiple sources). This may be a valid configuration if you trust all respective sources.

### Package Pattern Syntax
Expand Down Expand Up @@ -165,7 +152,7 @@ For manual onboarding you may take the following steps:
1. Run [dotnet restore](/dotnet/core/tools/dotnet-restore) to restore dependencies.
1. Run [`dotnet list package --include-transitive`](/dotnet/core/tools/dotnet-list-package#synopsis) to view all top-level and transitive packages in your solution.
* For .NET framework projects using [`packages.config`](../reference/packages-config.md), the `packages.config` file will have a flat list of all direct and transitive packages.
1. Define mappings such that every package ID in your solution - *including transitive packages* - matches a pattern for the target source.
1. Define mappings such that every package ID in your solution - _including transitive packages_ - matches a pattern for the target source.
1. Run [dotnet nuget locals global-packages -c](/dotnet/core/tools/dotnet-nuget-locals) to clear global-packages directory.
1. Run restore to validate that you have configured your mappings correctly. If your mappings don't fully cover every package ID in your solution, the error messages will help you identify the issue.
1. When restore succeeds, you are done! Optionally consider:
Expand All @@ -174,7 +161,7 @@ For manual onboarding you may take the following steps:

#### Automated onboarding using tool

Many repositories have a large number of packages and doing the work manually can be time consuming. The [NuGet.PackageSourceMapper tool](https://www.nuget.org/packages/NuGet.PackageSourceMapper) can automatically generate a NuGet.config for you, based on your project's known packages and sources.
Many repositories have a large number of packages and doing the work manually can be time consuming. The [NuGet.PackageSourceMapper tool](https://www.nuget.org/packages/NuGet.PackageSourceMapper) can automatically generate a NuGet.config for you, based on your project's known packages and sources.

The package source mapper tool requires you to have completed a successful package restore in which it will read each respective `.nupkg.metadata` file generated as part of your build to best understand how you map your respective packages and sources. Tool not only covers top dependencies it also considers all the transitive dependencies when generating mapping.

Expand All @@ -183,6 +170,7 @@ Tool has several option how to generate mapping pattern depending on your need,
For an idea of how your source mappings may look like, refer to our [samples repo](https://github.com/NuGet/Samples/tree/main/PackageSourceMappingExample).

> [!Note]
>
> * There are no nuget.exe or dotnet.exe commands for managing the package source mapping configuration, see [NuGet/Home#10735](https://github.com/NuGet/Home/issues/10735).
> * There are no means of mapping packages at package installation time, see [NuGet/Home#10730](https://github.com/NuGet/Home/issues/10730).
> * There is a limitation when using the `DotNetCoreCLI@2` Azure Pipelines task which can be worked around by using `feed-` prefixes in your source mapping configuration. It is recommended however to use `NuGetAuthenticate` for your authentication needs and call the dotnet cli directly from a script task. See [microsoft/azure-pipelines-tasks#15542](https://github.com/microsoft/azure-pipelines-tasks/issues/15542).
23 changes: 2 additions & 21 deletions docs/consume-packages/install-use-packages-visual-studio.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ ms.author: jodou
ms.date: 03/03/2025
ms.topic: conceptual
f1_keywords:
- "vs.toolsoptionspages.nuget_package_manager"
- "vs.toolsoptionspages.nuget_package_manager.general"
- "vs.toolsoptionspages.nuget_package_manager.package_sources"
- "vs.nuget.packagemanager.ui"
---

Expand Down Expand Up @@ -48,7 +45,7 @@ To find and install a NuGet package with Visual Studio, follow these steps:
> In Visual Studio 17.11 and higher, package owners are shown as profile hyperlinks when supported by the selected package source.
> Package ownership is defined by the package source. For example, see [Manage package owners on nuget.org](../nuget-org/publish-a-package.md#manage-package-owners-on-nugetorg).
>
> In Visual Studio 17.10 and earlier, the package _author_ metadata is shown, which appears as plain-text.
> In Visual Studio 17.10 and earlier, the package *author* metadata is shown, which appears as plain-text.
> For more information, see [Authors package metadata](../create-packages/package-authoring-best-practices.md#authors).

- Select a package to see detailed package information.
Expand Down Expand Up @@ -129,8 +126,6 @@ In this example, the ClassLibrary1 project is using EntityFramework 6.2.0, where

Visual Studio ignores the order of package sources, and uses the package from whichever source is the first to respond to a request. For more information, see [Restore packages](package-restore.md). For information about how to load a package from a specific source, see [Package source mapping](package-source-mapping.md).

To manage NuGet package sources, follow these steps:

1. To change the source from which Visual Studio loads package metadata, select a source from the **Package source** selector.

![Screenshot showing the Package source selector highlighted.](media/package-source-selector.png)
Expand All @@ -139,21 +134,7 @@ To manage NuGet package sources, follow these steps:

![Screenshot showing the Package source settings icon highlighted.](media/package-source-settings.png)

1. In the **Options** window, expand the **NuGet Package Manager** node and select **Package Sources**.

![Screenshot showing the Options window with Package Sources selected.](media/package-sources.png)

1. To add a source, select **+**, edit the **Name**, enter the URL or path in **Source**, and then select **Update**.

The source now appears in the **Package source** dropdown list.

1. To change a package source, select it, make edits in the **Name** and **Source** boxes, and select **Update**.

1. To disable a package source, clear the box to the left of the name in the list.

1. To remove a package source, select it, and then select the **X** button.

If a package source reappears after you delete it, it might be listed in a computer-level or user-level *NuGet.config* file. For the location of these files, see [Common NuGet configurations](../consume-packages/configuring-nuget-behavior.md). Remove the package source in the files by editing them manually or using the [nuget sources command](../reference/nuget-exe-CLI-reference.md).
1. To manage NuGet package sources, see [NuGet Options in Visual Studio](nuget-visual-studio-options.md#package-sources).

## NuGet Package Manager Options control

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ info : global-packages: /home/user1/.nuget/packages/
info : temp: /tmp/NuGetScratchuser1
info : plugins-cache: /home/user1/.local/share/NuGet/plugins-cache
```

To display the location of a single folder, use `http-cache`, `global-packages`, `temp`, or `plugins-cache` instead of `all`.

## Clearing local folders

### Command-line

If you encounter package installation problems or otherwise want to ensure that you're installing packages from a remote gallery, use the `locals --clear` option (dotnet.exe) or `locals -clear` (nuget.exe), specifying the folder to clear, or `all` to clear all folders:

```cli
Expand Down Expand Up @@ -103,9 +106,21 @@ nuget locals all -clear

Any packages used by projects that are currently open in Visual Studio are not cleared from the *global-packages* folder.

Starting in Visual Studio 2017, use the **Tools > NuGet Package Manager > Package Manager Settings** menu command, then select **Clear All NuGet Cache(s)**. Managing the cache isn't presently available through the Package Manager Console. In Visual Studio 2015, use the CLI commands instead.
### Visual Studio

Visual Studio supports clearing all local folders in the "NuGet Package Manager" options found under the **Tools > NuGet Package Manager > Package Manager Settings** menu command.

On the General page, select **Clear NuGet local resources**.
Once started, this action cannot be cancelled.
A progress bar will be shown and will contain the final status of the command.

The [Output Window](/visualstudio/ide/output-window) when selecting Show output from "Package Manager" will show additional details about the clear command, including any error messages.

![Clear NuGet local resources button highlighted in the General page of NuGet options](media/clear-nuget-local-resources.png)

Managing the cache isn't presently available through the Package Manager Console.

![NuGet option command for clearing caches](media/options-clear-caches.png)
For more information, see [NuGet Options in Visual Studio](nuget-visual-studio-options.md#clear-nuget-local-resources).

## Troubleshooting errors

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/consume-packages/media/package-sources.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading