I have a Project
instance, and I don't understand how to find out the project type/language. Specifically, I need to check for a C/C++ project.
The docs seem lacking.
Previously, another person added the following bit of magic to my open-source VS extension, and it worked in VS2013-2015:
private static bool isVisualCppProject(object project)
{
Type projectObjectType = project.GetType();
var projectInterface = projectObjectType.GetInterface("Microsoft.VisualStudio.VCProjectEngine.VCProject");
return projectInterface != null;
}
...
isVisualCppProject(project.Object);
But it no longer works in VS 2017 RC. And I would gladly get rid of this runtime reflection magic and un-typed object
and dynamic
instead of Project
- the code is already getting unmaintainable because of this.
you can determine project type via project extension name, and the following demo for your reference.
DTE2 dte = (DTE2)this.ServiceProvider.GetService(typeof(DTE));
Solution2 solution = (Solution2)dte.Solution;
foreach (Project p in solution.Projects)
{
string[] projectName = p.FullName.Split('.');
if (projectName.Length > 1)
{
string fileExt = projectName[projectName.Length-1];
if (fileExt == "vcxproj")
{
//is c/c++ porject
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With