How do you programmatically find & iterate all project & dll references within a Visual Studio 2010 solution?
I can iterate all projects and found the Project.ProjectItems
property and Project.Properties
but have not found any way to reference the references (pun intended).
This is happening in an add-in, so a DTE solution is preferable to anyone suggesting we iterate the files.
Proposed solution based on the answers below:
You need to find and include a reference to VSLangProj.dll (e.g. in Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies
)
Then you can iterate all selected project's project & DLL references like this:
foreach (Project project in (object[])_applicationObject.ActiveSolutionProjects)
{
VSProject vsProject = project.Object as VSProject;
if (vsProject != null)
{
foreach (Reference reference in vsProject.References)
{
// Do cool stuff here
}
}
}
Info for Tomas Lycken:
_applicationObject is a private member in my add-in, e.g.
private DTE2 _applicationObject;
I set it in the connection like this:
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;