I would like to add existing projects to a new solution generated by a template. Can I achieve this via vstemplate file or do I have to use IWizard. And if I have to use IWizard how can I correctly work with it. Currently I tried the following:
- multiproject template which adds some solution folders and one project
- wizard with custom wizarddata. $wizarddata$ contains some relative paths to projects which already exists on harddrive. In the wizard I select the basepath for these projects. How can I add this project now to my solution?
The main problem seems to be that the Solution object does not contain anything:
var type = Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
var dte2 = (EnvDTE80.DTE2)Activator.CreateInstance(type);
var solution = (EnvDTE100.Solution4)dte2.Solution;
var projects = dte2.ActiveSolutionProjects;
projects does not contain any project. The same applies for dte2.Solution.Projects. This code is called in the RunFinished function of the IWizard implementation. Or:
var type = Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
var dte2 = (EnvDTE80.DTE2)Activator.CreateInstance(type);
dte2.ExecuteCommand("File.AddExistingProject", "X:\\Path\\To\\Project\\ProjectName.csproj");
will throw an COM-Exception. If i execute the ExecuteCommand from a macro in a visual studio it will work fine. What am I doing wrong?
Ok I found the problem. The code snippet above with the creation of the DTE-Object does not work correct. If I remember the automationObject from the RunStarted function and will use it in the RunFinished function everything will work as expected: