all groups > dotnet windows forms designtime > may 2005 >
You're in the

dotnet windows forms designtime

group:

how to get list of assemblies referenced by the current project


how to get list of assemblies referenced by the current project mnowosad
5/17/2005 7:57:01 PM
dotnet windows forms designtime:
I am looking for a way, during design-time, to be able to access all
assemblies that were added as references to the currently selected project.

That would allow me, for instance, to open a control editor and populate a
list box with the names of all assemblies referenced by the project that the
control is part of.

I checked the available design-time services like ITypeResolutionService and
IReferenceService and none of them seem to be useful for that purpose.

So how I can do it?

Thanks,
Re: how to get list of assemblies referenced by the current project Francisco Padron
5/21/2005 8:12:13 PM
I think you have to go to the Visual Studio IDE automation interfaces
(EnvDTE.DTE) to get this.

I found this code in MSDN (sorry about the VB code, too lazy to translate):

Imports VSLangProj
Sub ListReferences()
' Retrieve the VSProject object.
Dim theVSProject As VSProject = _
CType(DTE.Solution.Projects.Item(1).Object, VSProject)

' Retrieve the references collection.
Dim refs As References = theVSProject.References

' Create a string list of the reference names.
Dim refList As String = ""
Dim aRef As Reference
For Each aRef In refs
refList &= aRef.Identity & ControlChars.CrLf
Next
MsgBox(refList)
End Sub

I think this code is for an add-in, however you can obtain the DTE from any
designer/control using GetService:

EnvDTE.DTE dte = (EnvDTE.DTE) Component.Site.GetService(typeof(EnvDTE.DTE));



I hope this helps.

--
Francisco Padron
www.chartfx.com


[quoted text, click to view]

Re: how to get list of assemblies referenced by the current projec mnowosad
5/23/2005 10:55:14 AM
Thanks for the answer. I actually had already found a similar code in the web
and it worked as expected. However, you gave me a better way to access the
DTE through the designer. I originally was making this Interop COM call:

EnvDTE.DTE dte = (EnvDTE.DTE)
System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.7.1");

Instead, after your suggestion, I am using this code, which is much more
compliant to the .NET Component design-time framework:

EnvDTE.DTE dte = (EnvDTE.DTE) Component.Site.GetService(typeof(EnvDTE.DTE));

Thanks again,
Marcos


[quoted text, click to view]
AddThis Social Bookmark Button