visual-studionuget-packagedependency-management

How to remove unused libraries from a visual studio solution


Writing my first vb.net VS2022 application involved a lot of experimentation while learning, adding then (only in a few cases) removing packages to the project. In the end, the \bin\debug folder contains a huge number of dlls which I'm sure I don't need. I was surprised to see the same files are also in the \Release folder. For example at one time I tried implementing "user-secrets" but then gave up after learning it doesn't do what I thought, by now I can't even remember where I typed in the user secret stuff, or if I deleted them, But there is a "Microsoft.Extensions.Configuration.UserSecrets.dll" in the \release folder, which I assumed is more minimal collection, and files such as .pdb are not needed if there is no debugging.

I see that the .vbproj file has a lot of <PackageReference Include=... lines which correspond to the many packages. Using "Remove unused references" reduced the number of these lines but the number of dlls and other stuff such as .pdb & .json files in the \release folder did not change.

There have been a lot of questions about this and a number of tools are mentioned in the answers. Alas, all of the threads are old and refer to VS 2010 or at best 2013.

Is there a up-to-date method or tool that can help with this clean up?

Else I will have to remove the dlls one at at time and test all the programs features to see what happens. Or perhaps deleting the <PackageReference Include=... lines one by one will remove the unnecessary dlls? Either way testing all the features of the program will take for ever, so the right tool will be best.


Solution

  • Regarding the issue of redundant DLL files in VB.NET projects in Visual Studio 2022, you can try the following suggestions:

    1: I recommend using the "Clean Solution" command first to delete all files in the \bin and \obj folders. This will delete all generated DLL and EXE files. You can then rebuild the solution and only the currently referenced DLL files will appear in the \bin folder.

    2: The .pdb file is a program database file that contains debugging information. If you don't need debugging information, you can set "Debug Information" to "None" in the "Build" tab of the project properties. This will prevent the .pdb file from being generated.