|
| 1 | +--- |
| 2 | +title: dotnet package update command |
| 3 | +description: Update PackageReferences in a project. |
| 4 | +author: zivkan |
| 5 | +ms.date: 10/03/2025 |
| 6 | +--- |
| 7 | +# dotnet package update |
| 8 | + |
| 9 | +**This article applies to:** ✔️ .NET 10 SDK and later versions |
| 10 | + |
| 11 | +## Name |
| 12 | + |
| 13 | +`dotnet package update` - Update referenced packages in a project. |
| 14 | + |
| 15 | +## Synopsis |
| 16 | + |
| 17 | +```dotnetcli |
| 18 | +dotnet package update [<packages>...] |
| 19 | + [--interactive] [--project <path>] |
| 20 | + [--verbosity <level>] [--vulnerable] |
| 21 | +
|
| 22 | +dotnet package update -h|--help |
| 23 | +``` |
| 24 | + |
| 25 | +## Description |
| 26 | + |
| 27 | +The `dotnet package update` command updates packages used by projects. |
| 28 | +If [NuGetAudit](/nuget/concepts/auditing-packages) is enabled, it can also attempt to automatically update update packages with known vulnerabilities to fixed versions. |
| 29 | + |
| 30 | +### Warnings as Errors |
| 31 | + |
| 32 | +`dotnet package update` does implicit restores to check if the resulting package graph is free of errors. |
| 33 | +Using `--vulnerable` also does an implicit restore to find NuGetAudit warnings. |
| 34 | +However, if your project uses `WarningsAsErrors` or `TreatWarningsAsErrors`, NuGet's restore warnings can cause restore to fail, preventing the update from completing. |
| 35 | + |
| 36 | +We recommend taking advantage of MSBuild conditions and environment variables as a workaround until [this feature request](https://github.com/NuGet/Home/issues/14311) is implemented. |
| 37 | +For example, set `<TreatWarningsAsErrors Condition=" '$(CustomCondition)' == ''>true</TreatWarningsAsErrors>` in your project, and then on most Linux and Mac shells you can run `CustomCondition=true dotnet package update`. |
| 38 | +On Windows Command Prompt and PowerShell, you will need to set the environment variable, run dotnet package update, then unset the environment variable as three separate commands. |
| 39 | + |
| 40 | +## Arguments |
| 41 | + |
| 42 | +- **`packages`** |
| 43 | + |
| 44 | + An optional list of packages to update. |
| 45 | + When no packages are provided, the command will attempt to update all packages referenced by the project. |
| 46 | + Packages can be a package name optionally followed by an `@` and a version number. |
| 47 | + For example, `dotnet package update Contoso.Utilities` or `dotnet package update Contoso.Utilities@3.2.1`. |
| 48 | + When no version is provided, it will find the highest version available on the configured package sources. |
| 49 | + |
| 50 | +## Options |
| 51 | + |
| 52 | +- **`--interactive`** |
| 53 | + |
| 54 | + Allows the command to stop and wait for user input or action (for example to complete authentication). |
| 55 | + |
| 56 | +- **`--project <path>`** |
| 57 | + |
| 58 | + The project which packages should be updated in. |
| 59 | + If a directory is provided, it searches for project and solution files in the directory. |
| 60 | + Defaults to the current working directory. |
| 61 | + |
| 62 | +- **`--verbosity`** |
| 63 | + |
| 64 | + Display this amount of details in the output: `[n]ormal`, `[m]inimal`, `[q]uiet`, `[d]etailed`, or `[diag]nostic`. The default is `normal`. |
| 65 | + |
| 66 | +- **`--vulnerable`** |
| 67 | + |
| 68 | + If restore reports any packages as having known vulnerabilities, this command will upgrade those packages. |
| 69 | + Using this option will upgrade packages to the lowest version that is higher than the currently referenced version, that does not have any known vulnerabilities. |
| 70 | + |
| 71 | +[!INCLUDE [help](../../../includes/cli-help.md)] |
| 72 | + |
| 73 | +## Examples |
| 74 | + |
| 75 | +- Update all packages in the project to the highest version available |
| 76 | + |
| 77 | + ```dotnetcli |
| 78 | + dotnet package update |
| 79 | + ``` |
| 80 | +
|
| 81 | + ```output |
| 82 | + Updating outdated packages in S:\src\test\update\ConsoleApp1. |
| 83 | + ConsoleApp1: |
| 84 | + Updated Microsoft.Extensions.Configuration 9.0.0 to 9.0.9. |
| 85 | + Updated Microsoft.Extensions.DependencyInjection 9.0.0 to 9.0.9. |
| 86 | +
|
| 87 | + Updated 2 packages in 7 scanned packages. |
| 88 | + ``` |
| 89 | +
|
| 90 | +- Update Contoso.Utilities to the highest version available, and Fabrikam.WebApi to version 1.2.3 |
| 91 | +
|
| 92 | + ```dotnetcli |
| 93 | + dotnet package update Contoso.Utilities Fabrikam.WebApi@1.2.3 |
| 94 | + ``` |
| 95 | +
|
| 96 | + ```output |
| 97 | + Updating outdated packages in S:\src\test\update\ConsoleApp1. |
| 98 | + ConsoleApp1: |
| 99 | + Updated Contoso.Utilities 2.3.1 to 2.4.6. |
| 100 | + Updated Fabrikam.WebApi 1.0.2 to 1.2.3. |
| 101 | +
|
| 102 | + Updated 2 packages in 2 scanned packages. |
| 103 | + ``` |
| 104 | +
|
| 105 | +- Update packages with known vulnerabilities |
| 106 | +
|
| 107 | + ```dotnetcli |
| 108 | + dotnet package update --vulnerable |
| 109 | + ``` |
| 110 | +
|
| 111 | + ```output |
| 112 | + Updating packages with security advisories in S:\src\test\update\ConsoleApp1 |
| 113 | + ConsoleApp1: |
| 114 | + Updating System.Text.Json 8.0.0 to 8.0.5. |
| 115 | +
|
| 116 | + Updated 1 packages in 31 scanned packages. |
| 117 | + ``` |
0 commit comments