I'm trying to create a filter (one of the little folders which does nothing but separate files in a project) in a visual studio (C++) project template with a wizard, so I'm writing the following code in the RunStarted method:
public void RunStarted(object automationObject,
Dictionary<string, string> replacementsDictionary,
WizardRunKind runKind, object[] customParams)
{
try
{
// Add filters to the project
EnvDTE.DTE dte = (EnvDTE.DTE)automationObject;
Array activeProjects = (Array)dte.ActiveSolutionProjects;
Project activeProj = (Project)activeProjects.GetValue(0);
VCProject prj = (VCProject)activeProj.ProjectItems.Item(0);
VCFilter filter = prj.AddFilter("Header_Files");
filter.AddFile("header.h");
prj.Save();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
This is failing though. The error returned is:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Array.InternalGetReference(Void* elemRef, Int32 rank, Int32* pIndices)
at System.Array.GetValue(Int32 index)
at my_wizard.IMyWizard.RunStarted(Object automationObject, Dictionary`2 replacementsDictionary, WizardRunKind runKind, Object[] customParams)
Where am I getting wrong? How can I add a filter to a vs template?