Skip to content

Instantly share code, notes, and snippets.

@chrisortman
Created May 26, 2011 21:10
Show Gist options
  • Save chrisortman/994090 to your computer and use it in GitHub Desktop.
Save chrisortman/994090 to your computer and use it in GitHub Desktop.
First stab at powershell function to check if project has a package
function Test-Project {
param(
#The package we are looking for
$PackageName
)
Process {
$hasPackage = $false
$packages = get-package $PackageName -First 1
foreach ($package in $packages) {
write-host "Checking $($package.Id) in $($_.ProjectName)"
$PackageID = $package.Id
$packageManager = $host.PrivateData.packageManagerFactory.CreatePackageManager()
$fileSystem = New-Object NuGet.PhysicalFileSystem($_.Properties.Item("FullPath").Value)
$repo = New-Object NuGet.PackageReferenceRepository($fileSystem, $packageManager.LocalRepository)
foreach ($package in $repo.GetPackages() | ? {$_.Id -eq $PackageID}) {
$hasPackage = $true;
}
}
if($hasPackage) { $_ }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment