GAT: Projects in Solution
Giocando con EnvDTE è possibile recupeare tutti i progetti di una solution su cui viene lanciata una recipe GAT.
Ecco il codice
using
System;
using
System.ComponentModel;
using
System.Data.Common;
using
System.Data;
using
System.Collections.Generic;
using
Microsoft.Practices.Common;
using
System.ComponentModel.Design;
using
System.Configuration;
using
Microsoft.Practices.RecipeFramework.VisualStudio;
using
System.IO;
using
System.Collections.Specialized;
using
System.Globalization;
using
EnvDTE;
using
System.Collections;
using
System.Windows.Forms;namespace DevLeap.Converters
{
public class ProjectsInSolutionConverter : StringConverter
{
// Indica se pu• essere chiamato il metodo GetStandardValuespublic override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
MessageBox.Show("Converter");
DTE dte = (DTE)context.GetService(typeof(DTE));List<String> values = new List<String>();foreach (Project p in dte.Solution.Projects)
{
values.Add(p.Name);
}
return new StandardValuesCollection(values);
}
}
}
In questo caso ho usato un custom converter per fornire i valori ad un argument della recipe: una volta che lo sviluppatore ha selezionato il progetto l'argument avrà il nome del progetto indicato. Tramite la action (presente in GAT) GetProjectAction è possibile risalire al EnvDTE.Project per effetturare operazioni sul progetto.