Skip to content

Instantly share code, notes, and snippets.

@herskinduk
Created September 18, 2014 11:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herskinduk/4528231150d13439e325 to your computer and use it in GitHub Desktop.
Save herskinduk/4528231150d13439e325 to your computer and use it in GitHub Desktop.
<#@ template hostspecific="true" language="C#" #>
<#@ output extension=".txt" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="VSLangProj" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ assembly name="EnvDTE" #>
<#@ import namespace="EnvDTE" #>
<#
IServiceProvider serviceProvider = (IServiceProvider)this.Host;
DTE dte = serviceProvider.GetService(typeof(DTE)) as DTE;
foreach(Project project in dte.Solution.Projects)
{
WriteLine(project.Name);
foreach(VSLangProj.Reference reference in CollectReferences(project))
{
WriteLine("+ " + reference.Name);
}
}
#>
<#+
public static IEnumerable<VSLangProj.Reference> CollectReferences(EnvDTE.Project project)
{
var vsproject = project.Object as VSLangProj.VSProject;
if (vsproject != null)
{
foreach (VSLangProj.Reference reference in vsproject.References)
{
if (reference.SourceProject == null)
{
yield return reference;
}
else
{
// This is a project reference
}
}
}
}
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment