Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove solution folders using NuGet uninstall.ps

In my NuGet package, I add a solution folder using the method shown here: https://stackoverflow.com/a/6478804/1628707

Here's my code to add the solution folder, in Init.ps.

$solutionFolder = $solution.AddSolutionFolder("build")
$folderItems = Get-Interface $solutionFolder.ProjectItems ([EnvDTE.ProjectItems])
$files = Get-ChildItem "$buildFolder"
foreach ($file in $files)
{
    $folderItems.AddFromFile($file.FullName)
}

Now, in Uninstall.ps, I want to remove the solution folder named "build." I've tried the following.

//try to get the solution folder. This fails with 'doesn't contain a method named Item'
$proj = $solution.Projects.Item("build")

//So, I tried enumerating and finding the item by name. This works.
foreach ($proj in $solution.Projects)
{
  if ($proj.Name -eq "build")
  {
    $buildFolder = $proj
  }
}

//But then removing fails with 'doesn't contain a method named Remove'
$solution.Remove($buildFolder)

I'm stymied and will appreciate any suggestions.

like image 503
Charles Flatt Avatar asked Nov 13 '22 15:11

Charles Flatt


1 Answers

Not sure why Item is being difficult but another way to do this would be:

$proj = $solution.Projects | Where {$_.ProjectName -eq "build"}
like image 50
Keith Hill Avatar answered Dec 26 '22 12:12

Keith Hill