title: Using EnvDTE and VSLangProj in powershell :
body: <p>I have a solution with 1 web application project. I'm trying to add three c# class library projects to it and then add project references of these three projects to the existing web application project. I'm doing this using powershell. I'm able to add the three projects to the solution, but I can't figure out how to add the project references to the existing project. I understand I have to use VSLangProj.VSProject in order to get access to the references, but I Keep getting a conversion error. </p>
  
  <p>Here is the error: </p>
  
  <p>Cannot convert the "System._<em>ComObject" value of type "System.</em>_ComObject#{b1042570-25c6-424a-b58b-56fa83aa828a}" to type "VSLangProj.VSProject".</p>
  
  <p>Here is the relevant code I have so far.</p>
  
  <pre><code>[void][System.Reflection.Assembly]::LoadWithPartialName("envdte.dll")
  [void][System.Reflection.Assembly]::LoadWithPartialName("envdte80.dll")
  [void][System.Reflection.Assembly]::LoadWithPartialName("VSLangProj.dll")
  [void][System.Reflection.Assembly]::LoadWithPartialName("VSLangProj80.dll")
  
  $envdte = [System.Runtime.InteropServices.Marshal]::GetActiveObject("VisualStudio.DTE.12.0")
  
  
      $envdte.Solution.Open($FullPathtoSolution)
  
      $envdte.Solution.AddFromFile($FUllPathtoNewProject1)
  $envdte.Solution.AddFromFile($FUllPathtoNewProject2)
  $envdte.Solution.AddFromFile($FUllPathtoNewProject3) 
  
      $envdte.Solution.SaveAs($FullPathtoSolution)
  
      foreach ($proj in $envdte.Solution.Projects)
                 {
                      $proj.Kind #Prints {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
          $proj.Name #Prints the name of my web application project like it should
          $vsproj = [VSLangProj.VSProject]$proj.Object #this line causes the error
          $vsproj.References.AddProject($NewProject1Name)
                      $vsproj.References.AddProject($NewProject2Name)
                      $vsproj.References.AddProject($NewProject3Name)
                  }
  
  
  
  $envdte.Solution.SaveAs($FullPathtoSolution)
  </code></pre>