Skip to content

Add dotnet nuget why documentation #30497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions docs/core/tools/dotnet-nuget-why.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: dotnet nuget why command
description: The 'dotnet nuget why' command provides the user to view the dependency graph of a package.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: The 'dotnet nuget why' command provides the user to view the dependency graph of a package.
description: The 'dotnet nuget why' command shows the dependency graph of a package.

ms.date: 08/04/2022
---
# dotnet nuget why

**This article applies to:** ✔️ .NET Core 3.1 SDK and later versions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which preview is this in? We will want to make sure it doesn't get merged before it's available, and this applies-to text should be updated to .NET 7 Preview SDK.


## Name

`dotnet nuget why` - Prints the dependency graph for a package.

## Synopsis

```dotnetcli
dotnet nuget why [<PROJECT>|<SOLUTION>] [<PACKAGE_NAME>]
[--framework <FRAMEWORK>]
dotnet nuget why -h|--help
```

## Description

The `dotnet list package` command provides a way to print out the dependency graph for a package to allow users to understand the nature of top-level packages and their transitive dependencies. This command is dependent on the `project.assets.json` file being present in the project. The following example shows the output of the `dotnet nuget why` command for `packageA` which has dependencies in `projectNameA` and `projectNameB`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be easier to understand with actual command output using real package/project names rather than packageA and B and projectA and B.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `dotnet list package` command provides a way to print out the dependency graph for a package to allow users to understand the nature of top-level packages and their transitive dependencies. This command is dependent on the `project.assets.json` file being present in the project. The following example shows the output of the `dotnet nuget why` command for `packageA` which has dependencies in `projectNameA` and `projectNameB`:
The `dotnet nuget why` command provides a way to print out the dependency graph for a package to allow users to understand the nature of top-level packages and their transitive dependencies. This command is dependent on the `project.assets.json` file being present in the project. The following example shows the output of the `dotnet nuget why` command for `packageA` which has dependencies in `projectNameA` and `projectNameB`:


```output
Project 'projectNameA' has the following dependency graph for 'packageA'
[net6.0]:
Microsoft.ML (1.0.0) -> Microsoft.ML.Util (1.0.0) -> packageA (1.0.0)
[net472]:
Microsoft.ML (1.0.0) -> Microsoft.ML.Util (1.0.0) -> packageA (1.0.0)

Project 'projectNameB' has the following dependency graph for 'packageA'
[net6.0]:
Microsoft.ML (1.1.0) -> Microsoft.ML.Util (1.1.0) -> packageA (1.1.0)
[net472]:
Microsoft.ML (1.1.0) -> Microsoft.ML.Util (1.1.0) -> packageA (1.1.0)
```

Use the `--framework` option to find the dependency graph of a package in a specific framework.

The following example shows the output of the `dotnet nuget why packageA --framework net6.0` command for the same package as the previous example:

```output
Project 'projectNameA' has the following dependency graph for 'packageA'
[net6.0]:
Microsoft.ML (1.0.0) -> Microsoft.ML.Util (1.0.0) -> packageA (1.0.0)
```

## Arguments

`PROJECT | SOLUTION`

The project or solution file to operate on. If not specified, the command searches the current directory for one. If more than one solution or project is found, an error is thrown.

`PACKAGE_NAME`

The exact package name/id for which the dependency graph has to be identified. Package name wildcards are not supported.

## Options

- **`--framework <FRAMEWORK>`**

The NuGet sources to use when searching for newer packages. Requires the `--outdated` option.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --outdated option isn't in the doc here.


## Examples

- Print dependency graph of `packageA` in a specific framework:

```dotnetcli
dotnet nuget why packageA --framework net6.0
```

- Print dependency graph of `packageA`, the package has dependencies in multiple projects so all dependencies are printed by default:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Print dependency graph of `packageA`, the package has dependencies in multiple projects so all dependencies are printed by default:
- Print dependency graph of `packageA`. The package has dependencies in multiple projects so all dependencies are printed by default:

But the command only looks at one project per the arguments section, so it's not clear what this means by referring to multiple projects.


```dotnetcli
dotnet nuget why packageA
```