Using EnvDTE and VSLangProj in powershell:

I have a solution with 1 web application project. I am trying to add three C # class library projects to it, and then add links to the projects of these three projects in an existing web application project. I do this using powershell. I can add three projects to the solution, but I cannot figure out how to add project links to an existing project. I understand that I need to use VSLangProj.VSProject to access the links, but I keep getting the conversion error.

Here is the error:

Cannot convert the value of "System._ComObject" to the type "System._ComObject # {b1042570-25c6-424a-b58b-56fa83aa828a}" to enter "VSLangProj.VSProject".

Here is the relevant code that I have.

[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)
+3
2

VSLangProj.VSProject VSLangProj80.VSProject2. :

$vsproj = [VSLangProj.VSProject]$proj.Object

:

$vsproj = [VSLangProj80.VSProject2]$proj.Object

VSProject2 MSDN ( , GuidAttribute).

+1

VSProject, EnvDte.Project.Object VSProject Visual Basic Visual #. ( #):

if (project.Kind == VSLangProj.PrjKind.prjKindCSharpProject)
{
    var vsproj = (VSLangProj.VSProject)project.Object;
    vsproj.References.Add(...);
}
0

All Articles