Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
It seems we have a lot of unreferenced files pointing to deleted files in our projects (under a solution in VS2008 and VS2012).

For example, we stopped using a bitmap; we removed the file on disk, remove the resource ID and entry in the RC file, but we forgot to remove the entry in the solution.

The entry is there and does nothing.

It is worse for header files; it seems in some instances, in VS2012 the project will try to rebuild if there is such an unreferenced file.

So, question:

Is there a way to clean up those unreferenced files in Visual Studio ?

Could it be done with a macro ? (i.e. loop over the files in the solution/project, try to open them, and if cannot, remove from solution/project )

Thanks.

Max
Posted
Comments
Sergey Alexandrovich Kryukov 2-Jul-13 19:18pm    
This is a great idea, but I would extend it to a number of other things: redundant referenced assemblies, solution-global removal of unused "using" and so on. Anyway, I voted 5 for posing this problem.
I doubt that the available solution exists (but not sure); and it would be a great "feature request" message to Microsoft (if Microsoft was responsive to good suggestions :-).
—SA
H.Brydon 2-Jul-13 23:01pm    
I wish I could +5 that comment. :-)

Watch for a proxy upvote...
Sergey Alexandrovich Kryukov 2-Jul-13 23:25pm    
Thank you, Harvey. You see, we still have some good questions, rarely. :-)
—SA

1 solution

You said "solution" but I think you meant "project" in a few places.

There is no macro or automated way that I am aware of to do this. You need to do it manually. It is not a lot of work, but it needs to be done manually. If you open the solution and project in the Visual Studio IDE, the missing files will show up in the solution view with a read "X" icon. Simply right click and remove those files from the project. I have VS2010 and found that some versions of it require you to manually save the projects to properly forget about the missing files. In any case, do all of this and exit the IDE (click "yes" to save anything of interest) and things should be the way you want.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-Jul-13 23:39pm    
This is quite a useful advice, but by far insufficient. However, as you are not supposed to create a publish the whole perfect VS add-on in response to a question, I think it deserves my 5.

As to the VS add-ons, I would be careful. It's always better to have no add-ons at all than carry a less-then-always-useful one. For example, I once strongly opposed one CodeProject article which I considered as totally idiotic: the author created a way to automatically add "using System" to file where it was forgotten. I failed to explain to the poor guy that "System" is not always to be used, and much less "using System". So the add-on would deliver a purely negative quality, in other words, pure harm.

In contrast, cleaning of projects from redundancies is much, much more important. Actually, VS tends to create way too much redundancies, and this is easy to explain: Microsoft tends to remember about the weak-minded beginners, who would need everything working right away, at the cost of leanness. For example, one thing I strongly dislike is setting the output paths to that bin/Debug and bin/Release, and then all those directories are copied multiple times to that output directory of the entry-point projects of a solution. This is good in one sense: if you create projects by default and reference them at the level of solution, it all works right away. But for nice solution structure, faster build and better disk usage, it's much better to merge all output directories to one (somewhere at ../../../*). I would be rather pleased by such "solution refactorization" feature...

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900