Question

In Visual Studio 2010 (or 2012) is there a way to locate all references in code that mention any class/method defined in a referenced dll.

Currently I have two processes that I use (depending on the situation):

  • The first one involves just deleting the dll reference from the project and then making a note of all the build error locations.
  • The other way is to open the reference in the Object Browser and then expand to it's namespaces, and for each namespace I do a manual search, but this doesn't always help find all references and because the legacy code has the same namespaces spanning multiple assemblies there's a lot of noise to filter through.

Neither of these are really ideal solutions, is there any easier way to do this? perhaps via a VS extension.

Was it helpful?

Solution

You can find this if you install Resharper:

Expand the References and choose Find code Dependent on Module

enter image description here

The results then appear like:

enter image description here

OTHER TIPS

Don't have Resharper, but you do have Sublime Text?

in Sublime Text, select 'open folder', and select the folder containing the solution. Then select menu item Find -> Find in Files...

In the 'Where:' field, enter:

*.scsproj

Then in the 'Find:' field, search for the string

Include="[full namespaced name of library]"

for example:

Include="System.Xml.Linq"

will find all projects that reference the System.Xml.Linq dll in the solution.

Don't have any Extension?

Just write a piece of code... easiest... I find it very easy to edit, via code, the project file..

  private static List<string> FindAllRefrences(ref int ctr, string dir, string projectToSearch)
    {
        List<string> refs = new List<string>();
        foreach (var projFile in Directory.GetFiles(dir, "*.csproj", SearchOption.AllDirectories))
        {
            if (projFile.IndexOf(projectToSearch, StringComparison.OrdinalIgnoreCase) >= 0)
                continue;
            //var t = false;
            var lines = File.ReadAllLines(projFile);

            foreach (var line in lines)
            {
                if (line.IndexOf(projectToSearch, StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    ctr++;
                    refs.Add(projFile);
                    break;
                }
            }
        }

        return refs;
    }

Steps for doing this in Visual Studio 2019:

  1. Expand the project in the Solution Explorer.
  2. Expand the References section.
  3. Right click the reference that corresponds to the dll in question (should have the same name).
  4. Select View in Object Browser.
  5. Expand the object that corresponds to your dll.
  6. Expand the namespace
  7. Right click the class and select Find All References.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top