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.
Here is the error:
Cannot convert the "System._ComObject" value of type "System._ComObject#{b1042570-25c6-424a-b58b-56fa83aa828a}" to type "VSLangProj.VSProject".
Here is the relevant code I have so far.
[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)