我正在尝试在包管理器控制台中使用 powershell 来编写从解决方案中删除项目的脚本,但我遇到了令人惊讶的困难。
我可以很容易地添加一个项目
PM> $dte.Solution.AddFromFile("C:\Dev\Project1.csproj")
现在我想删除一个项目,但什么也做不了。
我尝试了很多事情,包括:
PM> $project1 = Get-Project "Project1Name"
PM> $dte.Solution.Remove($project1)
>
无法将参数“0”,值为:“System.__ComObject”,“删除”转换为
键入“EnvDTE.Project”:“无法转换类型的“System.__ComObject”值
“System.__ComObject#{866311e6-c887-4143-9833-645f5b93f6f1}”键入
“EnvDTE.Project”。
PM> $project = Get-Interface $project1 ([EnvDTE.Project])
PM> $dte.Solution.Remove($project)
Cannot convert argument "0", with value: "System.__ComObject", for "Remove" to
type "EnvDTE.Project": "Cannot convert the "System.__ComObject" value of type
"NuGetConsole.Host.PowerShell.Implementation.PSTypeWrapper" to type
"EnvDTE.Project"."
PM> $project = [EnvDTE.Project] ($project1)
Cannot convert the "System.__ComObject" value of type
"System.__ComObject#{866311e6-c887-4143-9833-645f5b93f6f1}" to type
"EnvDTE.Project".
PM> $solution2 = Get-Interface $dte.Solution ([EnvDTE80.Solution2])
PM> $solution2.Remove($project1)
Exception calling "Remove" with "1" argument(s): "Exception calling
"InvokeMethod" with "3" argument(s): "Object must implement IConvertible.""
PM> $dte2 = Get-Interface $dte ([EnvDTE80.DTE2])
PM> $dte2.Solution.Remove($project)
Method invocation failed because [System.Object[]] doesn't contain a method
named 'Remove'.
我尝试过其他组合,但我显然在旋转我的轮子。我很感激任何建议。