How to know which other projects refer to a certain project in Visual Studio?
A

4

55

In Visual Studio, for a class, a field, a method, I can just right click and say "Find All References" to see who is calling my code.

But there is no similar thing for a project.

What is the simplest way to do so? Do I have to check every project to tell?

Edit: enter image description here

A refers to B, but can not find B using Regex.

Alcoholicity answered 6/3, 2012 at 22:36 Comment(3)
Are you trying to find what projects reference a given project?Agathy
Yes, that is what I meant. Sorry if my English confused you.Charles
The simple approach is to just remove the project reference and recompile.Maharanee
B
56
  1. Find All (CTRL+SHIFT+F)
  2. "Find what:" = Reference.*ReplaceThisTextWithProjectName
  3. Check "Use:" -> "Regular Expression" in the "Find options" section
  4. "Look at these file types:" = "*.*proj* "
  5. "Look in:" = Select a directory/folder on your drive. Don't use "Entire Solution" it won't get to the project file itself. (Don't forget to check "Include sub-folders")
Borrego answered 6/3, 2012 at 23:5 Comment(3)
I've edited the search criteria to include the following:5. "Look in:" = Select a directory/folder on your drive. DOn't use "Entire Solution" it won't get to the project file itself.Borrego
Excellent.. very helpful.. :)Domenicadomenico
Newer answer - grayed out project dependencies.Hardwood
T
32

Right click on solution => Project dependencies. Then you choose your project in the drop down box. All projects greyed out below are depending on the selected project. (They are greyed out so you cannot create circular dependencies by checking them.)

Tripalmitin answered 8/6, 2021 at 14:43 Comment(3)
For those looking for an answer in 2022, this is easier and more reliable than using the Find option above.Cheriecherilyn
I'm not sure why, but this didn't work for me. The referencing projects were indeed greyed out, but so were other projects that didn't reference the target project. (This is on a .NET Framework class library, and it's definitely not a targeting issue.)Hackworth
@Hackworth Maybe it's recursive? A references B, B references C, so for C, both A and B are greyed out?Tripalmitin
S
7

Not sure if you've looked into using Resharper (not free), but it easily allows you to right-click on a project to see dependent code.

I can't live without and well worth the cost in my opinion - but it's not for everyone.

http://www.jetbrains.com/resharper/webhelp/Navigation_and_Search__Finding_Usages__Finding_Dependencies_and_Referenced_Code.html

There's a 30 day trial if you want to try it out - P.S I don't work for them, just a lover of the tool! :)

http://www.jetbrains.com/resharper/

Skyscraper answered 6/3, 2012 at 23:18 Comment(2)
I don't think this does what op wants. It only searches for things referencing the project within the current solution .... and not outside solutions.Givens
The link is deadKoontz
L
1

Search all Project Files in editor like Notepad++

A similar approach to fenone's answer is to go to your solution folder in Windows and simply filter on *.*proj there through Windows search. That'll give you all your project files (or maybe you have some in a different folder, they can be added later). Simply select all these files and open in an editor like Notepad++. You can add other projects to your Notepad++ instance as desired. Once you've got your project files all opened there, it's easy to search for references to projects, .dlls, libraries, whatever. I prefer this approach because the project files are off in their own editor and they are easier to search in my opinion.

Unload Project and Recompile

A second approach would be to right click your project in Visual Studio's Solution Explorer and click "Unload Project", then analyze or recompile the solution. Any projects that actual reference the unloaded project in code will have errors, but your build will still be successful and your project level references will still show as being valid (at least they are for me in VS 2017). A similar more invasive approach that invalidates project level references and actually fails any referencing build would be to change your project folder's path so that Visual Studios can't find it. This would have the secondary affect of also identifying any references setup by path instead of by project.

Other Considerations

Of course, your project could be included in other solutions, so similar search techniques can be used across solutions. Just to cover your bases, there might be references to your compiled file by path instead of by project, that's just something to be aware of. Check you post-build events to make sure nothing is being copied and referenced somewhere unexpected. Search for all instances of your .dll or whatever in some reasonable folder scope, just to be aware of any copies.

Longspur answered 12/7, 2018 at 21:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.