Pregunta

The method Solution.Projects.Index(Object index) get an index of project as number.

I have the name of the project. How can I determine the index in the solution of this project programmatically?

¿Fue útil?

Solución

You can use linq:

string yourProject = "ProjectName";
var query = Solution.Projects.Cast<Project>()
            .Select((p, i) => new { Name = p.Name, Index = i})
            .First(p => p.Name == yourProject).Index;

Otros consejos

If you have the name of the project, you could loop through all the projects to find the index of the desired project:

int index = 0;
foreach(Project project in dte.Solution.Projects)
{
    if (string.Equals(project.Name, "desired project name"))
    {
        break;
    }
    index++;
}

On the other hand why do you actually need the index of the project? You can use Item method with project name as parameter as well.

The value passed to index is an integer that is an index to a Project object in its collection. The value of index can alternatively be a string value that equates to the name of a project in the collection.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top