PRB: System.NotImplementedException calling EnvDTE.Project.Delete from a Visual Studio macro or add-in.

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio .NET 2002
Date: May 2011   Microsoft Visual Studio .NET 2003
      Microsoft Visual Studio 2005
      Microsoft Visual Studio 2008
      Microsoft Visual Studio 2010

The automation model (EnvDTE) of Visual Studio provides the EnvDTE.Project.Delete method to delete a project of a solution. However, when that method is called, you get a System.NotImplementedException. As a workaround, you can use the EnvDTE.Solution.Remove method to remove the project from the solution and then delete the folder of the project using the System.IO.Directory.Delete method.

More Information

The following macro shows the code to delete the first project a solution that reproduces the problem and the workaround:

Language: VB.NET   Copy Code Copy Code (IE only)
Sub DeleteProject()

   Dim folder As String
   Dim prj As Project


      prj = DTE.Solution.Projects.Item(1)

      ' This causes System.NotImplementedException
      ' prj.Delete()

      folder = System.IO.Path.GetDirectoryName(prj.FullName)


      System.IO.Directory.Delete(folder, True)

   Catch ex As Exception
   End Try

End Sub

Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)