querying packages for a project

Dec 14, 2010 at 1:06 AM

I am trying to find a way to determine which packages are applied to a project from the powershell commands or from the global variables in the powershell console.  It does not seem to be exposed through any of the publicly defined API.  Is this information available through the $packageManagerFactory ?

Developer
Dec 14, 2010 at 1:52 AM

File a bug, there might already be one for this though. We should have Get-Package -Project.

To get this from powershell isn't trivial, I'll post a workaround for you.

Dec 14, 2010 at 1:55 AM

created bug http://nuget.codeplex.com/workitem/467

Developer
Dec 14, 2010 at 2:08 AM

Here's the bug http://nuget.codeplex.com/workitem/245

Developer
Dec 14, 2010 at 2:21 AM

You can work around this for now by doing this:

$packageManager = $packageManagerFactory.CreatePackageManager()
$fileSystem = New-Object NuGet.PhysicalFileSystem($project.Properties.Item("FullPath").Value)
$repo = new-object NuGet.PackageReferenceRepository($fileSystem, $packageManager.LocalRepository)

The above code assumes you have a reference to the project in the $project variable.

Dec 14, 2010 at 2:26 AM

by reference to $project do you mean:

$project = Get-Project [name]

???

Developer
Dec 14, 2010 at 2:33 AM

Yep

Dec 14, 2010 at 3:13 AM

works like a charm.. thanks

$repo.GetPackages() | select id,version
gives me the packages and version for a specifc project.
Dec 14, 2010 at 3:49 AM

ok.. so now I want to uninstall-package for a specifc project... now that I know what is installed. http://nuget.codeplex.com/workitem/470  I created a work item to allow this scenerio

Dec 14, 2010 at 5:39 AM

the Uninstall-Package cmdlet does have the -project parameter. Didn't it work for you? If not, can you describe what you did?

Developer
Dec 14, 2010 at 5:42 AM

There's no way to only uninstall from a project. The solution level packages should be seen as a cache that can be used cross project. Install/Uninstall/Update commands all work on projects. We have some detection for solution vs project level so each of those commands does whatever is necessary at solution and project level depending on the package.

Dec 14, 2010 at 10:53 AM

Hmm ok I did a test last not on uninstall, for a package that was installed into mutliple projects, the command looked like it only removed the references from the active project. It did remove the files from the packages folder.. I will try this on a clean setup and see what happens, and create a repro.

The latest wiki doc did not show a- project param on the uninstall. So I did not dig further. I remember the params being added and removed since ctp1.

sent from my mobile

On Dec 14, 2010 12:43 AM, "dfowler" <notifications@codeplex.com> wrote:
> From: dfowler
>
> There's no way to only uninstall from a project. The solution level packages should be seen as a cache that can be used cross project. Install/Uninstall/Update commands all work on projects. We have some detection for solution vs project level so each of those commands does whatever is necessary at solution and project level depending on the package.
>
>
Dec 14, 2010 at 4:28 PM

It should only get removed from the packages folder if it is no longer used by any projects.  Otherwise references could be broken, since they point there.  So if I understand you correctly, what you observed is expected.