title: Remove project from solution via Package Manager Console
body: <p>I am trying to use powershell within the Package Manager Console to script the removal of a project from a solution and I am having a surprisingly hard time.</p>
  
  <p>I can easily add a project by</p>
  
  <pre><code>PM&gt; <b>$dte.Solution.AddFromFile("C:\Dev\Project1.csproj")</b></code></pre>
  
  <p>Now I want to be remove a project and can't get anything to work.</p>
  
  <p>I have tried a number of things including:</p>
  
  <pre><code>PM&gt; <b>$project1 = Get-Project "Project1Name"</b>
  PM&gt; <b>$dte.Solution.Remove($project1)</b></code>>
  
  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"."</pre>
  
  <pre><code>PM&gt; <b>$project = Get-Interface $project1 ([EnvDTE.Project])</b>
  PM&gt; <b>$dte.Solution.Remove($project)</b>
  
  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"."</code></pre>
  
  <pre><code>PM&gt; <b>$project = [EnvDTE.Project] ($project1)</b>
  
  Cannot convert the "System.__ComObject" value of type
  "System.__ComObject#{866311e6-c887-4143-9833-645f5b93f6f1}" to type
  "EnvDTE.Project".</code></pre>
  
  <pre><code>PM&gt; <b>$solution2 = Get-Interface $dte.Solution ([EnvDTE80.Solution2])</b>
  PM&gt; <b>$solution2.Remove($project1)</b>
  
  Exception calling "Remove" with "1" argument(s): "Exception calling
  "InvokeMethod" with "3" argument(s): "Object must implement IConvertible.""</code></pre>
  
  <pre><code>PM&gt; <b>$dte2 = Get-Interface $dte ([EnvDTE80.DTE2])</b>
  PM&gt; <b>$dte2.Solution.Remove($project)</b>
  
  Method invocation failed because [System.Object[]] doesn't contain a method
  named 'Remove'.</code></pre>
  
  <p>I have tried other combinations, but I am clearly spinning my wheels. I appreciate any suggestions.</p>