davidfowl/NuGetPowerTools — Issue #13: Projects in solution folders cause Enable-PackageRestore to fail
Author: i8beef
Created: 2011-11-10 17:13:56+00:00
State: open

Took me a minute to figure out what's happening, but it appears that if a project exists under a Solution folder and you run Enable-PackageRestore, the PowerShell command will fail with the following:

Get-MSBuildProject : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take
pipeline input.
At F:\Projects\GenericApplicationFramework\src\packages\NuGetPowerTools.0.29\tools\MSBuild.psm1:84 char:48
+ $buildProject = $_ | Get-MSBuildProject <<<<
+ CategoryInfo : InvalidArgument: (:) [Get-MSBuildProject], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Get-MSBuildProject

Failed to add import 'NuGet.targets' to GenericApplicationFramework.UI.MVC.Tests
Enabled package restore for GenericApplicationFramework.UI.MVC
Get-MSBuildProject : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take
pipeline input.
At F:\Projects\GenericApplicationFramework\src\packages\NuGetPowerTools.0.29\tools\MSBuild.psm1:58 char:52
+ $buildProject = $_ | Get-MSBuildProject <<<<
+ CategoryInfo : InvalidArgument: (:) [Get-MSBuildProject], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Get-MSBuildProject

You cannot call a method on a null-valued expression.
At F:\Projects\GenericApplicationFramework\src\packages\NuGetPowerTools.0.29\tools\MSBuild.psm1:59 char:38
+ $buildProject.SetProperty <<<< ($PropertyName, $PropertyValue) | Out-Null
+ CategoryInfo : InvalidOperation: (SetProperty:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At F:\Projects\GenericApplicationFramework\src\packages\NuGetPowerTools.0.29\tools\MSBuild.psm1:60 char:20
+ $_.Save <<<< ()
+ CategoryInfo : InvalidOperation: (Save:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Taking all projects out of the solution folder fixes this, so a possible workaround is to move them all out to the root of the solution, run the command, and then move them all back.

My powershell isn't good enough, or rather my understanding of how it's getting the list of projects isn't good enough, to fix it myself and submit a pull request.