使用NuGet uninstall.ps删除解决方案文件夹

Cha*_*att 5 powershell nuget

在我的NuGet包中,我使用此处显示的方法添加解决方案文件夹:https: //stackoverflow.com/a/6478804/1628707

这是我在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)
}
Run Code Online (Sandbox Code Playgroud)

现在,在Uninstall.ps中,我想删除名为"build"的解决方案文件夹.我尝试了以下内容.

//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)
Run Code Online (Sandbox Code Playgroud)

我受到了阻碍,并会欣赏任何建议.

Kei*_*ill 1

不知道为什么 Item 很难,但另一种方法是:

$proj = $solution.Projects | Where {$_.ProjectName -eq "build"}
Run Code Online (Sandbox Code Playgroud)