Search code examples
javascriptiteratorenvdteenumerator

Running over ENVDTE Solution Projects


I'm writing a C++ Project template in VS 2010 using the Custom Wizard technique.

In the default.js, the file which holds the behind JavaScript code, I want to take the current generated project, and locate it in an existing VS solution, in a specific "apps" subfolder.

I have a C# working code which does the above, but I have to rewrite it in JavaScript.

My C# code is:

Projects ps = solution.Projects;


var item = ps.GetEnumerator();
while (item.MoveNext())
{
      var project = item.Current as Project;
      string name = project.Name;
      if (name == "apps")
      {
         SolutionFolder folder = (SolutionFolder)project.Object;
         p = folder.AddFromFile(newProjDir + "\\" + projName + ".vcxproj");
      }
}

In JavaScript, I wrote:

var ps = Solution.Projects;

But now I don't succeed to iterate over the projects, as I did in c#.

When I'm trying to write in the JS file:

var item = ps.GetEnumerator();

I'm getting the run time error:

Object doesn't support this property or method

Do you know about any way to iterate over the Projects collection? Is there a JS function which behaves like GetEnumerator()?


Solution

  • I found my way:

    for (var i = 1; i <= solution.Projects.Count; i++) 
            {
                if(Solution.Projects.Item(i).Name == "apps")        
                {
                    appsFolder = Solution.Projects.Item(i);
                    project = appsFolder.Object.AddFromFile(newProjectPath + "\\" + strProjectName + "\\" + strProjectName + ".vcxproj");
                    break;
                }
            }
    

    Thanks you all for trying help :)