1

I want, via the nuget console, to list project that has a specific package installed.

Ex :

get-project -all | get-package | ?{ $_.Id -like 'ThePackage' } | `
    <Here I have all the packages, but I can't access the project name>

The last part should be something like Select-Object project.Name, but get-package does not return the project name, just the package information.

2
  • I got so confused when I came to this question, I was like hmm I don't remember asking this question Commented Nov 30, 2017 at 16:55
  • 1
    I got confused too when I saw that comment, I was like hmm I don't remember leaving this comment Commented Dec 2, 2017 at 2:04

2 Answers 2

3

Yeah, this could be better. One way to do this is to take advantage of the fact that get-package will accept a filter on project:

Get-Project | foreach-object {
    get-package -ProjectName $_.Name | `
    Add-Member -MemberType NoteProperty -Name ProjectName -Value $_.Name -passthru
    }  | select id, projectname | ft -auto -GroupBy projectname

I'm adding the projectname property the each package before grouping on this property at the end.

Edit by Johnny5 : To get the exact result I wanted, I edited the command like this :

Get-Project -all | foreach-object { get-package -ProjectName $_.Name | `
    Add-Member -MemberType NoteProperty -Name ProjectName -Value $_.Name -passthru
} | where-object { $_.id -eq 'Id.Of.The.Package' } | select id, projectname
Sign up to request clarification or add additional context in comments.

4 Comments

% is the alias for ForEach ?
Thanks, I acheived what I wanted from your command. It would be nice if you add some explanation on % and Add-Member command :-)
The percentage is the foreach-object command (you can find this out by running get-help %. You can find out about add-member with get-help add-member.
I moved the where-object (alias: ?) in front of the select
0

With version 2.0.0.0 of the Get-Package cmdlet, there is an entry returned for each usage of a package within a project - and the project name is included.

Check your version of Get-Package with the following command in the Package Manager Console within Visual Studio.

get-command get-package

Find all of the projects that have a specific package installed using the following command.

get-package newtonsoft.json

If you are interested in finding any packages for which projects within the solution reference different versions, then try the following command. It should display a list of packages. You can choose one, hit OK and it will show you the projects that reference them.

get-package | group-object Id | %{$versions = ($_.Group | Group-object Version); if(($versions | measure-object).Count -gt 1){$versions;};} | %{$_.Group} | group-object Id, Version | sort-object Name | Out-GridView -OutputMode Single | %{$_.Group} | select-object -first 1 | %{ $version = $_.Version; get-package $_.Id;} | ?{$_.Version -eq $version}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.