locoboy
locoboy

Reputation: 38940

How do you determine which libraries are not being used

In developing a test project I've tried a lot of things which includes declaring an enormous amount of references/libraries. As a result I have a ton of declared libraries that are not being used in my project and would like to flush them out. Is there a way to know which libraries are not in use by the end product's code? I'm hoping there is some kind of visual studio function that can tell me this.

Thanks!

Upvotes: 4

Views: 1828

Answers (4)

lucdm
lucdm

Reputation: 143

In Visual Studio 2019 starting from the latest versions and Visual Studio 2022 you can remove unused packages, but only for SDK style projects. If you try on old projects, like .Net Framework, you won't see this option. As workaround, to verify, you can create two simply console apps: one using .Net Core or later, and one .Net Framework 4.7 or 4.8.

Just right-click on project name and select Remove Unused References


Please refer to: Remove Unused References

Upvotes: 0

Icemanind
Icemanind

Reputation: 48686

Coderush is similar to Resharper, but they offer a free Xpress version on their website. You can go download that and it should show you which are unused (although I'm not 100% the Xpress version has this ability).

Upvotes: 2

Hans Passant
Hans Passant

Reputation: 941625

You can only easily find out what assemblies are used. Easy enough to invert the list. Look at the .assembly directives that the compiler put in the assembly manifest with ildasm.exe or Reflector. The compiler whittles down the list to assemblies that contains types that it encountered while compiling the code. Watch out for assemblies you load yourself.

Upvotes: 1

SaravananArumugam
SaravananArumugam

Reputation: 3720

Solution is handy. Just follow the link

How to: Remove Unused References

EDITED:

Since the above option is available only in VB.NET, you can go for some Visual Studio 2010 plug ins. Looks like Resharper does it. Please refer to Visual Studio: Detecting unneeded Assemblies for more detail.

Upvotes: 2

Related Questions