Created
May 26, 2011 21:10
-
-
Save chrisortman/994090 to your computer and use it in GitHub Desktop.
First stab at powershell function to check if project has a package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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