2012-12-17 25 views
5

Trong gói NuGet, tôi thêm một thư mục giải pháp sử dụng phương pháp đưa ra ở đây: https://stackoverflow.com/a/6478804/1628707Remove giải pháp thư mục sử dụng NuGet uninstall.ps

Dưới đây là mã của tôi để thêm thư mục giải pháp, trong 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) 
} 

Bây giờ, trong Uninstall.ps, tôi muốn xóa thư mục giải pháp có tên "build". Tôi đã thử những điều sau đây.

//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) 

Tôi bị cản trở và sẽ đánh giá cao bất kỳ đề xuất nào.

+1

Cậu làm việc này? –

+0

Tôi gặp sự cố với vấn đề tương tự nhưng đã cố gắng giải quyết vấn đề. Xem [this] (http://stackoverflow.com/questions/17769227/remove-project-from-solution-via-package-manager-console/28483691#28483691) – AHowgego

Trả lời

1

Không chắc chắn tại sao mục được khó khăn nhưng một cách khác để làm điều này sẽ là:

$proj = $solution.Projects | Where {$_.ProjectName -eq "build"} 
Các vấn đề liên quan