locked
Add reference to a project. RRS feed

  • Question

  • I've create two project using a template (EnvDTE.Solution2.AddFromTemplate). And now i want to add a refrence in project2 to project1.
    I'm try with some samples but it does not work.

    First try: 
    VSLangProj.VSProject vsProject = (VSLangProj.VSProject)proj.Object;
    vsProject.References.Add("MyLibrary");


    This code not work because VSLangProj don have VSProject instead has SVsProjectItem but SVsProjectItem  doesn't has References.

    Second Try:

    //Add dependency test project depen on new created 
    projectBuildDependency bldDepends = solution.SolutionBuild.BuildDependencies.Item(project2.UniqueName);
    bldDepends.AddProject(project1.UniqueName);


    Any ideas?
    Thanks in advance.
    Monday, September 11, 2017 1:50 PM

Answers

  • I found the solution.

    The problem was a missing reference to VSLangProj

    My final code:

    VSLangProj.VSProject vsProject = (VSLangProj.VSProject)project2.Object;               
    vsProject.References.AddProject(project1);

    Monday, September 11, 2017 3:49 PM