Environment
The Microsoft.Blueprints.Contrib project contains a series of helper objects for working within the Visual Studio Environment.
EnvironmentManager
The EnvironmentManager class allows you easy access to the projects and solutions within Visual Studio. The EnvironmentManager is used in conjunction with the
ProjectSelector Dialog.
var environmentManager = new EnvironmentManager(context);
if (environmentManager.SolutionExplorerNode != SolutionExplorerNode.Project)
{
using (ProjectSelector projectSelector = new ProjectSelector(context))
{
projectSelector.PopulateProjectList();
if (projectSelector.ShowDialog() == DialogResult.OK)
{
environmentManager.SelectProject(projectSelector.SelectedProject);
}
else
{
throw new OperationCanceledException("User cancelled the Project selection dialog.");
}
}
}
Once the T4 Templates have been transformed by the
T4TemplateBuilder you can pass the resulting template collection to the EnvironmentManager to be added to a specific Visual Studio Project:
// add all transformed files to the project the user clicked on
List<string> files = templates.Select(t => t.TargetFileName).ToList();
this.environmentManager.AddProjectItemsToSelectedProject(files);