How to determine a project type by examin code model
I would like to make an add-in that can examine an already loaded project through the DTE and make a copy of it using the code model. I know that you may be wondering why - this is proof-of-concept for something else.
I run into the problem right off the bat with trying to create the new project. In order to create a new project, I have to use the Solution.AddFromTemplate method. There is no other way to add a new project that I have seen. (if there is please tell me!)
In order to use the AddFromTemplate, I need to know what kind of project I'm creating - Winform, Webform, console app etc. Trying to examine an existing project using the Code Model doesnt contain this infotmation (makes sense, it doesnt need it anymore).
Can anyone reccommend another way to accomplish this task? I want to take advantage of the Templates as much as possible.
Bill
Here is an example of how you can do this using DTE
void ProjectLanguage(DTE dte)
{
String lang = "";
foreach (Project p in dte.Solution)
{
CodeModel cm = p.CodeModel;
if (cm.Language == CodeModelLanguageConstants.vsCMLanguageCSharp)
{
lang = "CSharp";
}
else if (cm.Language == CodeModelLanguageConstants.vsCMLanguageVB)
{
lang = "Visual Basic";
}
else if (cm.Language == CodeModelLanguageConstants.vsCMLanguageVC)
{
lang = "Visual C++";
}
else
{
lang = "other";
}
Console.WriteLine("project language: " + lang);
}
}