Tôi đang cố gắng sử dụng PowerShell trong Package Manager Console để viết kịch bản việc xóa một dự án khỏi một giải pháp và tôi gặp phải một thời gian khó khăn đáng ngạc nhiên.Xóa dự án khỏi giải pháp thông qua Package Manager Console
tôi có thể dễ dàng thêm một dự án bởi
PM> $dte.Solution.AddFromFile("C:\Dev\Project1.csproj")
Bây giờ tôi muốn được loại bỏ một dự án và không thể có được bất cứ điều gì để làm việc.
Tôi đã thử một số điều bao gồm:
PM> $project1 = Get-Project "Project1Name"
PM> $dte.Solution.Remove($project1)
>
Cannot convert argument "0", with value: "System.__ComObject", for "Remove" to
type "EnvDTE.Project": "Cannot convert the "System.__ComObject" value of type
"System.__ComObject#{866311e6-c887-4143-9833-645f5b93f6f1}" to type
"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'.
Tôi đã cố gắng kết hợp khác, nhưng tôi quay rõ ràng bánh xe của tôi. Tôi đánh giá cao bất kỳ đề xuất nào.
Bạn có làm việc này không? Tôi có nhu cầu tương tự. –