Skip to content
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

Add support for dotnet list package command #1320

Closed
wants to merge 14 commits into from
Closed

Conversation

mishra14
Copy link
Contributor

@mishra14 mishra14 commented Apr 14, 2017

This PR adds support for dotnet list package command in NuGet. Fixes part of NuGet/Home#4102

Spec

Description

The command is used to list the package references for a project. The command allows filtering on package id and framework.

-help

F:\validation\test> & 'E:\nuget.client\artifacts\NuGet.CommandLine.XPlat\15.0\bin\Debug\net46\win7-x86\NuGet.CommandLine.XPlat.exe' package list -h


Usage: NuGet.CommandLine.XPlat.dll package list [options]

Options:
  -h|--help               Show help information
  --force-english-output  Forces the application to run using an invariant, English-based culture.
  --package               Id of the package for listing references.
  -p|--project            Path to the project file.
  -f|--framework          Frameworks for which the package reference should be listed.

Usage

csproj file -

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>netstandard2.0;netcoreapp1.0</TargetFrameworks>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="nuget.versioning" Version="4.0.0" />
  </ItemGroup>  
  <ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.0'">
    <PackageReference Include="newtonsoft.json" Version="9.0.1" />
  </ItemGroup>
  <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
    <PackageReference Include="newtonsoft.json" Version="10.0.2" />
  </ItemGroup>
</Project>

Example 1

Unconditional to print all references.

F:\validation\test> & 'E:\nuget.client\artifacts\NuGet.CommandLine.XPlat\15.0\bin\Debug\net46\win7-x86\NuGet.CommandLine.XPlat.exe' package list --project .\test.csproj
info : Project '.\test.csproj' has following package references per framework -
info : Framework 'All Frameworks' -
info : --------------------------------------------------
info : Package 'nuget.versioning' Version '4.0.0'.
info : --------------------------------------------------
info : Framework 'netstandard2.0' -
info : --------------------------------------------------
info : Package 'NETStandard.Library' Version '1.6.1'.
info : Package 'nuget.versioning' Version '4.0.0'.
info : Package 'newtonsoft.json' Version '10.0.2'.
info : --------------------------------------------------
info : Framework 'netcoreapp1.0' -
info : --------------------------------------------------
info : Package 'Microsoft.NETCore.App' Version '1.0.4'.
info : Package 'nuget.versioning' Version '4.0.0'.
info : Package 'newtonsoft.json' Version '9.0.1'.
info : --------------------------------------------------

Example 2

References for a framework.

F:\validation\test> & 'E:\nuget.client\artifacts\NuGet.CommandLine.XPlat\15.0\bin\Debug\net46\win7-x86\NuGet.CommandLine.XPlat.exe' package list --project .\test.csproj --framework netcoreapp1.0
info : Project '.\test.csproj' has following package references per framework -
info : Framework 'netcoreapp1.0' -
info : --------------------------------------------------
info : Package 'Microsoft.NETCore.App' Version '1.0.4'.
info : Package 'nuget.versioning' Version '4.0.0'.
info : Package 'newtonsoft.json' Version '9.0.1'.
info : --------------------------------------------------

Example 3

References for a package.

F:\validation\test> & 'E:\nuget.client\artifacts\NuGet.CommandLine.XPlat\15.0\bin\Debug\net46\win7-x86\NuGet.CommandLine.XPlat.exe' package list --project .\test.csproj --package newtonsoft.json
info : Project '.\test.csproj' has following package references per framework -
info : Framework 'All Frameworks' -
info : --------------------------------------------------
info : This poject does not reference package 'newtonsoft.json' for framework 'All Frameworks'.
info : --------------------------------------------------
info : Framework 'netstandard2.0' -
info : --------------------------------------------------
info : Package 'newtonsoft.json' Version '10.0.2'.
info : --------------------------------------------------
info : Framework 'netcoreapp1.0' -
info : --------------------------------------------------
info : Package 'newtonsoft.json' Version '9.0.1'.
info : --------------------------------------------------

Example 4

Random inputs.

F:\validation\test> & 'E:\nuget.client\artifacts\NuGet.CommandLine.XPlat\15.0\bin\Debug\net46\win7-x86\NuGet.CommandLine.XPlat.exe' package list --project .\test.csproj --framework random_framework
info : Project '.\test.csproj' has following package references per framework -
info : Framework 'random_framework' -
info : --------------------------------------------------
info : This poject does not target framework 'random_framework'.
info : --------------------------------------------------

@mishra14 mishra14 changed the title [WIP]Add support for dotnet list package command Add support for dotnet list package command Apr 14, 2017
@mishra14
Copy link
Contributor Author

mishra14 commented Apr 14, 2017

Discussed a bit with @emgarten anfd @alpaix:

Better UI possibility -

F:\validation\test> & 'E:\nuget.client\artifacts\NuGet.CommandLine.XPlat\15.0\bin\Debug\net46\win7-x86\NuGet.CommandLine.XPlat.exe' package list --project .\test.csproj
info : Project '.\test.csproj' has following package references per framework -
info :    |
info :    +---All Frameworks
info :    |      +---nuget.versioning 4.0.0.
info :    |
info :    +---netstandard2.0
info :    |      +---NETStandard.Library 1.6.1.
info :    |      +---nuget.versioning 4.0.0.
info :    |      +---newtonsoft.json 10.0.2.
info :    |
info :    +---netcoreapp1.0
info :          +---Microsoft.NETCore.App 1.0.4.
info :          +---nuget.versioning 4.0.0.
info :          +---newtonsoft.json 9.0.1.
info :
F:\validation\test> & 'E:\nuget.client\artifacts\NuGet.CommandLine.XPlat\15.0\bin\Debug\net46\win7-x86\NuGet.CommandLine.XPlat.exe' package list --project .\test.csproj --package newtonsoft.json
info : Project '.\test.csproj' has following package references per framework -
info :    |
info :    +---All Frameworks
info :    |      +---This poject does not reference package 'newtonsoft.json' for framework 'All Frameworks'.
info :    |
info :    +---netstandard2.0
info :    |      +---newtonsoft.json 10.0.2.
info :    |
info :    +---netcoreapp1.0
info :          +---newtonsoft.json 9.0.1.
info :
F:\validation\test> & 'E:\nuget.client\artifacts\NuGet.CommandLine.XPlat\15.0\bin\Debug\net46\win7-x86\NuGet.CommandLine.XPlat.exe' package list --project .\test.csproj --framework netcoreapp1.0
info : Project '.\test.csproj' has following package references per framework -
info :    |
info :    +---netcoreapp1.0
info :          +---Microsoft.NETCore.App 1.0.4.
info :          +---nuget.versioning 4.0.0.
info :          +---newtonsoft.json 9.0.1.
info :

var frameworks = listPkg.Option(
"-f|--framework",
Strings.ListPkg_FrameworksDescription,
CommandOptionType.SingleValue);
Copy link
Member

Choose a reason for hiding this comment

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

It looks like down below this is splitting the value. I would instead expect this to take MultipleValue so it is handled for you. Possibly the other inputs should allow multiple also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is consistent with other dotnet package commands.


private static void ValidateProjectPath(CommandOption projectPath, string commandName)
{
if (!File.Exists(projectPath.Value()) || !projectPath.Value().EndsWith("proj", StringComparison.OrdinalIgnoreCase))
Copy link
Member

Choose a reason for hiding this comment

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

what does this return if the option was not given? will this be a null ref?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

projectPath cannot be null, otherwise the command will throw help.

@mishra14
Copy link
Contributor Author

mishra14 commented May 9, 2017

@anangaur can you take a look at the UI here?

@kri5t
Copy link

kri5t commented Sep 5, 2017

I am right now using the dotnet platform to build a bunch of microservices. This feature would be perfect in a CI software to list all the dependencies of a project and send the data to a central database for visualisation. Which in turn will make it easier to understand which nuget packages is consumed in which projects.

It would be very nice if you would consider the possiblity of a more machine friendly format such as json or xml as the output.

@emgarten
Copy link
Member

emgarten commented Sep 5, 2017

@kri5t the list command displays all packages from a feed.

To get the dependencies of a project take a look at obj\project.assets.json

@mishra14 mishra14 closed this Nov 10, 2017
@mishra14 mishra14 deleted the dev-anmishr-list branch April 3, 2018 17:42
@mishra14 mishra14 restored the dev-anmishr-list branch July 10, 2018 23:09
@mishra14 mishra14 deleted the dev-anmishr-list branch July 10, 2018 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants