使用 NuGet 的 uninstall.ps 来移除解决方案文件夹

5
在我的NuGet包中,我使用这里展示的方法添加解决方案文件夹:https://dev59.com/KGw15IYBdhLWcg3wqNuM#6478804 以下是我在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
你解决了这个问题吗? - Srikanth Venugopalan
我之前遇到了类似的问题,但是现在已经解决了。请参考这个链接 - AHowgego
1个回答

1

不确定为什么Item会有困难,但另一种方法是:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接