You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `dotnet add package` command provides a convenient option to add or update a package reference in a project file. When you run the command, there's a compatibility check to ensure the package is compatible with the frameworks in the project. If the check passes and the package isn't referenced in the project file, a `<PackageReference>` element is added to the project file. If the check passes and the package is already referenced in the project file, the `<PackageReference>` element is updated to the latest compatible version. After the project file is updated, [dotnet restore](dotnet-restore.md) is run.
27
+
The `dotnet package add` command provides a convenient option to add or update a package reference in a project file. When you run the command, there's a compatibility check to ensure the package is compatible with the frameworks in the project. If the check passes and the package isn't referenced in the project file, a `<PackageReference>` element is added to the project file. If the check passes and the package is already referenced in the project file, the `<PackageReference>` element is updated to the latest compatible version. After the project file is updated, [dotnet restore](dotnet-restore.md) is run.
28
28
29
29
For example, adding `Microsoft.EntityFrameworkCore` to *ToDo.csproj* produces output similar to the following example:
30
30
@@ -57,7 +57,7 @@ The following scenarios are currently supported. These examples assume that the
57
57
58
58
Scenario 1: `<PackageReference>` does not exist in the project file, `<PackageVersion>` element does not exist in the `Directory.Packages.props file`, and the version argument is not passed from the commandline.
59
59
60
-
CLI command that is executed: `dotnet add ToDo.csproj package Microsoft.EntityFrameworkCore`
60
+
CLI command that is executed: `dotnet package add Microsoft.EntityFrameworkCore --project ToDo.csproj`
61
61
62
62
The `<PackageVersion>` element is added to the `Directory.Packages.props file`.
63
63
@@ -73,7 +73,7 @@ Scenario 1: `<PackageReference>` does not exist in the project file, `<PackageVe
73
73
74
74
Scenario 2: `<PackageReference>` does not exist in the project file, `<PackageVersion>` element does not exist in the `Directory.Packages.props file`, and the version argument is passed from the commandline.
75
75
76
-
CLI command that is executed: `dotnet add ToDo.csproj package Microsoft.EntityFrameworkCore --version 5.0.4`
76
+
CLI command that is executed: `dotnet package add Microsoft.EntityFrameworkCore --version 5.0.4 --project ToDo.csproj`
77
77
78
78
The `<PackageVersion>` element is added to the `Directory.Packages.props file`.
79
79
@@ -89,7 +89,7 @@ Scenario 2: `<PackageReference>` does not exist in the project file, `<PackageVe
89
89
90
90
Scenario 3: `<PackageReference>` does not exist in the project file, `<PackageVersion>` element does exist in the `Directory.Packages.props file`, and the version argument is not passed from the commandline.
91
91
92
-
CLI command that is executed: `dotnet add ToDo.csproj package Microsoft.EntityFrameworkCore`
92
+
CLI command that is executed: `dotnet package add Microsoft.EntityFrameworkCore --project ToDo.csproj`
93
93
94
94
The `<PackageVersion>` element is added to the `Directory.Packages.props file`.
95
95
@@ -105,7 +105,7 @@ The `<PackageReference>` element is added to the project file.
105
105
106
106
Scenario 4: `<PackageReference>` does not exist in the project file, `<PackageVersion>` element does exist in the `Directory.Packages.props file`, and the version argument is passed from the commandline.
107
107
108
-
CLI command that is executed: `dotnet add ToDo.csproj package Microsoft.EntityFrameworkCore --version 5.0.4`
108
+
CLI command that is executed: `dotnet package add Microsoft.EntityFrameworkCore --version 5.0.4 --project ToDo.csproj`
109
109
110
110
The `<PackageVersion>` element is added to the `Directory.Packages.props file`.
111
111
@@ -168,19 +168,19 @@ Scenario 4: `<PackageReference>` does not exist in the project file, `<PackageVe
168
168
- Add `Microsoft.EntityFrameworkCore` NuGet package to a project:
169
169
170
170
```dotnetcli
171
-
dotnet add package Microsoft.EntityFrameworkCore
171
+
dotnet package add Microsoft.EntityFrameworkCore
172
172
```
173
173
174
174
- Add a specific version of a package to a project:
The `dotnet list package` command provides a convenient option to list all NuGet package references for a specific project or a solution. You first need to build the project in order to have the assets needed for this command to process. The following example shows the output of the `dotnet list package` command for the [SentimentAnalysis](https://github.com/dotnet/samples/tree/main/machine-learning/tutorials/SentimentAnalysis) project:
31
+
The `dotnet package list` command provides a convenient option to list all NuGet package references for a specific project or a solution. You first need to build the project in order to have the assets needed for this command to process. The following example shows the output of the `dotnet package list` command for the [SentimentAnalysis](https://github.com/dotnet/samples/tree/main/machine-learning/tutorials/SentimentAnalysis) project:
32
32
33
33
```output
34
34
Project 'SentimentAnalysis' has the following package references
@@ -44,7 +44,7 @@ The **Requested** column refers to the package version specified in the project
44
44
45
45
Use the `--outdated` option to find out if there are newer versions available of the packages you're using in your projects. By default, `--outdated` lists the latest stable packages unless the resolved version is also a prerelease version. To include prerelease versions when listing newer versions, also specify the `--include-prerelease` option. To update a package to the latest version, use [dotnet add package](dotnet-add-package.md).
46
46
47
-
The following example shows the output of the `dotnet list package --outdated --include-prerelease` command for the same project as the previous example:
47
+
The following example shows the output of the `dotnet package list --outdated --include-prerelease` command for the same project as the previous example:
48
48
49
49
```output
50
50
The following sources were used:
@@ -57,7 +57,7 @@ Project `SentimentAnalysis` has the following updates to its packages
57
57
> Microsoft.ML 1.4.0 1.4.0 1.5.0-preview
58
58
```
59
59
60
-
If you need to find out whether your project has transitive dependencies, use the `--include-transitive` option. Transitive dependencies occur when you add a package to your project that in turn relies on another package. The following example shows the output from running the `dotnet list package --include-transitive` command for the [HelloPlugin](https://github.com/dotnet/samples/tree/main/core/extensions/AppWithPlugin/HelloPlugin) project, which displays top-level packages and the packages they depend on:
60
+
If you need to find out whether your project has transitive dependencies, use the `--include-transitive` option. Transitive dependencies occur when you add a package to your project that in turn relies on another package. The following example shows the output from running the `dotnet package list --include-transitive` command for the [HelloPlugin](https://github.com/dotnet/samples/tree/main/core/extensions/AppWithPlugin/HelloPlugin) project, which displays top-level packages and the packages they depend on:
61
61
62
62
```output
63
63
Project 'HelloPlugin' has the following package references
@@ -133,41 +133,41 @@ The project or solution file to operate on. If not specified, the command search
133
133
- List package references of a specific project:
134
134
135
135
```dotnetcli
136
-
dotnet list SentimentAnalysis.csproj package
136
+
dotnet package list --project SentimentAnalysis.csproj
137
137
```
138
138
139
139
- List package references that have newer versions available, including prerelease versions:
140
140
141
141
```dotnetcli
142
-
dotnet list package --outdated --include-prerelease
142
+
dotnet package list --outdated --include-prerelease
143
143
```
144
144
145
145
- List package references for a specific target framework:
146
146
147
147
```dotnetcli
148
-
dotnet list package --framework netcoreapp3.0
148
+
dotnet package list --framework netcoreapp3.0
149
149
```
150
150
151
151
- List package references in machine readable json output format:
152
152
153
153
```dotnetcli
154
-
dotnet list package --format json
154
+
dotnet package list --format json
155
155
```
156
156
157
157
- List package references for a specific target framework in machine readable json output format:
158
158
159
159
```dotnetcli
160
-
dotnet list package --framework netcoreapp3.0 --format json
160
+
dotnet package list --framework netcoreapp3.0 --format json
161
161
```
162
162
163
163
- Save machine readable json output of package references, including transitive dependency and vulnerability details into a file:
164
164
165
165
```dotnetcli
166
-
dotnet list package --include-transitive --vulnerable --format json >> dependencyReport.json
166
+
dotnet package list --include-transitive --vulnerable --format json >> dependencyReport.json
167
167
```
168
168
169
169
- List package references in machine readable json output format with output version 1:
170
170
171
171
```dotnetcli
172
-
dotnet list package --format json --output-version 1
172
+
dotnet package list --format json --output-version 1
The `dotnet add reference` command provides a convenient option to add project references to a project. After running the command, the `<ProjectReference>` elements are added to the project file.
25
+
The `dotnet reference add` command provides a convenient option to add project references to a project. After running the command, the `<ProjectReference>` elements are added to the project file.
26
26
27
27
```xml
28
28
<ItemGroup>
@@ -69,17 +69,17 @@ There's no CLI command to add a reference to an assembly that isn't in a project
0 commit comments