I have recorded a macro with me selecting a project and removing it from the solution, resulting in this code:
DTE.ActiveWindow.Object.GetItem("PerfixEMS\Allocations\BDAUploader\perFIXAllocationsFTP").Select(vsUISelectionType.vsUISelectionTypeSelect)
DTE.ExecuteCommand("Edit.Delete")
This macro works nicely if the project is in the solution, but causes a runtime error if it has already been removed. Even assigning the result if GetItem to an Object variable, to check for Nothing before calling Select, causes a runtime error. How can I error proof this macro?
You can put that in a
Tryblock:Update: I think your macro is not very safe. It uses active window and that window could be any window. I suggest something like this:
Project is referenced by its
UniqueNameproperty here. That name is projects path relative to the solution and its file extension. You can explore the properties by running a macro under the macro debugger. Projects can also be referenced by their 1-based index (DTE.Solution.Projects.Item(1)).