有没有办法自动删除Visual Studio项目/解决方案中的未引用文件?

有没有办法自动删除Visual Studio项目/解决方案中的未引用文件?

问题描述:

我们的项目中有很多未引用的文件指向已删除的文件(在VS2008和VS2012的解决方案下)。



例如,我们停止了使用位图;我们删除了磁盘上的文件,删除了RC文件中的资源ID和条目,但我们忘记删除解决方案中的条目。



条目在那里,什么都不做。



头文件更糟糕;在某些情况下,在VS2012中,如果有这样一个未引用的文件,项目将尝试重建。



所以,问题:



有没有办法在Visual Studio中清理那些未引用的文件?



可以用宏来完成吗? (即循环解决方案/项目中的文件,尝试打开它们,如果不能,则从解决方案/项目中删除)



谢谢。



Max

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

你说解决方案,但我认为你的意思是项目在几个地方。



我没有意识到这样做的宏观或自动方式。你需要手动完成。这不是很多工作,但需要手动完成。如果在Visual Studio IDE中打开解决方案和项目,则缺少的文件将显示在解决方案视图中,并显示X图标。只需右键单击并从项目中删除这些文件即可。我有VS2010并发现它的某些版本需要您手动保存项目以正确忘记丢失的文件。在任何情况下,执行所有操作并退出IDE(单击是以保存任何感兴趣的内容),事情应该是您想要的。
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.