![]() |
||||
|
Introduction This article provides information about how to guess the type of a project (Windows, executable or class library, Web Site, Web application, etc.) from a Visual Studio macro or add-in. You can have, at least, the following project types:
More Information The first property to use to determine the type of a project is EnvDTE.Project.Kind, which returns a Guid (since Visual Studio is so extensible, it must accommodate unknown project types and therefore it can not be an enum). You must add some assembly references such as VSLangProj.dll, etc. to your project to get the definition of some well-known Guid values and other classes or interfaces. See the article INFO: Assemblies used in Visual Studio Extensibility. Among others, EnvDTE.Project.Kind can take these values:
Also, you can check the availability of project extenders to guess the type of a project. You can check the presence of an extender in a project with this function: Public Function ProjectHasExtender(ByVal proj as EnvDTE.Project, ByVal extenderName As String) As Boolean Dim bResult As Boolean = False Dim colExtenderNames() As Object Dim objExtenderName As Object Try ' We could use proj.Extender(extenderName) but it causes an exception if not present and
' therefore it can cause performance problems if called multiple times. We use instead:
colExtenderNames = DirectCast(proj.ExtenderNames, Object())
If colExtenderNames.Length > 0 Then For Each objExtenderName In colExtenderNames
If objExtenderName.ToString = extenderName Then
bResult = True
Exit For
End If
Next
End If Catch objException As Exception
' Ignore
End Try
Return bResult End Function Some well-known extender names are:
You can distinguish Windows from Web applications using the EnvDTE.Project.Properties.Item("ProjectType") property, which can take these values:
For Windows applications you can guess the type using the property EnvDTE.Project.Properties.Item("OutputType"), which can take these values:
To guess the .NET language of a project see the article HOWTO: Get the language of a project or file from a Visual Studio .NET macro or add-in. The ultimate way of guessing the type / subtype of a project is to get its Guids. See the article HOWTO: Get the project flavour (subtype) of a Visual Studio project from an add-in. Related articles
Go back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this
You can code, design, locate code and document your apps much faster using VB.NET, C#, C++ or Visual J#:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||