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

时间:2012-12-17 17:13:43

标签: 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)
}

现在,在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)

我受到了阻碍,并会感激任何建议。

1 个答案:

答案 0 :(得分:1)

不确定为什么项目很难,但另一种方法是:

$proj = $solution.Projects | Where {$_.ProjectName -eq "build"}