HOWTO: Getting information specific to VB.NET and C# projects from an add-in or macro

Author:
Carlos Quintero MVP
COMMUNITY SOLUTIONS CONTENT DISCLAIMER
MICROSOFT CORPORATION AND/OR ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY, RELIABILITY, OR ACCURACY OF THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN. ALL SUCH INFORMATION AND RELATED GRAPHICS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT AND/OR ITS RESPECTIVE SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THIS INFORMATION AND RELATED GRAPHICS, INCLUDING ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, WORKMANLIKE EFFORT, TITLE AND NON-INFRINGEMENT. YOU SPECIFICALLY AGREE THAT IN NO EVENT SHALL MICROSOFT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, PUNITIVE, INCIDENTAL, SPECIAL, CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE, DATA OR PROFITS, ARISING OUT OF OR IN ANY WAY CONNECTED WITH THE USE OF OR INABILITY TO USE THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN, WHETHER BASED ON CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE, EVEN IF MICROSOFT OR ANY OF ITS SUPPLIERS HAS BEEN ADVISED OF THE POSSIBILITY OF DAMAGES.
This article has been archived. It is offered "as is" and will no longer be updated.
SUMMARY
This article describes how to get information not available in the general extensibility model of Visual Studio .NET (EnvDTE namespace) because it is specific to VB.NET and C# projects.
MORE INFORMATION
Visual Studio .NET supports many kind of projects (VB.NET, C#, C++, setup, database, etc.) and therefore the EnvDTE namespace provided by the EnvDTE.dll assembly only exposes the functionality common to all of them. For example, the information about references of VB.NET and C# projects, which do not apply to other kind of projects, is not exposed by that assembly. The extensibility model specific to VB.NET and C# projects resides in a different assembly named VSLangProj.dll. That assembly can be used in both Visual Studio .NET 2002 and 2003 (the later provides also a VSLangProj2.dll assembly with additional classes). You can get objects of the VSLangProj assembly from the objects of the EnvDTE assembly through its "Object" property. For example, you can cast the property EnvDTE.Project.Object to an VSLangProj.VSProject for VB.NET and C# projects. The following macro shows how to get the information about the references of a VB.NET or C# project:
 
Sub DisplayProjectReferences()
 
   Dim objProject As EnvDTE.Project
   Dim objVSProject As VSLangProj.VSProject
   Dim objReference As VSLangProj.Reference
   Dim sMsg As String
 
   Try
 
      For Each objProject In DTE.Solution.Projects
 
          If TypeOf objProject.Object Is VSLangProj.VSProject Then

              objVSProject = DirectCast(objProject.Object, VSLangProj.VSProject)
 
              sMsg = "References of project " & objProject.Name & ":" & CrLf & CrLf
 
              For Each objReference In objVSProject.References

                  sMsg &= objReference.Name

                  If objReference.SourceProject Is Nothing Then
                      sMsg &= " " & objReference.Version
                  Else
                      sMsg &= " (Source Project)"
                  End If

                  sMsg &= CrLf

              Next
 
              MessageBox.Show(sMsg)

          End If
 
      Next
 
   Catch objException As System.Exception
      MessageBox.Show(objException.ToString)
   End Try
 
End Sub
 
Properties

Article ID: 555467 - Last Review: 12/08/2015 01:31:01 - Revision: 1.0

Microsoft Visual Studio .NET 2002 Enterprise Developer, Microsoft Visual Studio .NET 2002 Professional Edition, Microsoft Visual Studio .NET 2003 Enterprise Architect, Microsoft Visual Studio .NET 2003 Enterprise Developer, Microsoft Visual Studio .NET 2003 Professional Edition

  • kbnosurvey kbarchive kbpubmvp kbpubtypecca kbhowto KB555467
Feedback