views:

87

answers:

4

IN VS2008, for C#, How can I figure out which references are needed and which are not? If you look in the solution explorer for a certain project and expand the references folder, is there a way to tell those that are never called? Will this be determined at compile time and simply not included?

+4  A: 

If they're not needed, the compiler won't add them to the assembly's manifest so it doesn't really hurt to have them there.

If you want to be obsessive-compulsive about it (like I often am :) then you can just delete one, rebuild and if there's an error add it back. If there's no errors, move on to the next one. The downside to doing that is if you delete a reference that you're not using now but you want to use it later, you have to remember which classes are in which assembly (e.g. if you delete System.Core, then you have to remember that System.Linq stuff is in there if you ever decide to use it later)

Dean Harding
I do the exact some thing since I am obsessive-compulsize about it. I do not like the extra references, because others may think they are required references. If I do include a reference that is not needed, I add readme.text in the root folder of the project and explain why I kept the reference.
AMissico
Moreover, references to third-party libraries always include those libraries in the output folder, so I always remove those that are not used.
AMissico
+4  A: 

Looks like Resharper is it. However I wouldn't worry too much about it as the unused assemblies are ignored by the compiler.

Igor Zevaka
+2  A: 

Reflector to the rescue again!

  1. File > Open > Your assembly
  2. Right-click the assembly in the left pane and select Analyze
  3. In the right pane, expand Depends On

This will generate a list of all of the assemblies it depends on, and all of their dependencies, all the way down to the turtles.

fatcat1111
+1  A: 

Stephan Brenner created an small tool to do that (http://www.stephan-brenner.com/?p=56) and If you want to create a solution for checking that in code there is an old post in MSDN (http://msdn.microsoft.com/en-us/magazine/cc163641.aspx) which does that. I hope this helps you.

Edgar Zavala