Reputation: 76258
Was wondering if there's an extension or macro or something that looks through your solution and gives out a report of which js/css/image files are not being referenced anywhere in code?
I have a large project and over time it has accumulated dust. Other than manually searching for each file's usage, is there any other time saving way?
Upvotes: 23
Views: 30302
Reputation: 1624
find all unused exports
Upvotes: 2
Reputation: 22466
Solution Features
Steps
dir /b
. Copy this into the clipboard (mark function) and paste into cell B2.=not(isna(VLOOKUP(B2,$A$2:$A$TheBottomOfA,1,false)))
. Alter TheBottomOfA to be the last used row in column A.Result
What you're looking at in Column B is a list of files you are not using.
Note
I recommend moving the unused files to an offline folder instead of deleting them.
Warning
You still need to use common sense. BRAIN=ON
Upvotes: 1
Reputation:
If you're using a new version of Visual Studio and can't use the extensions, what I did was this:
I've only had to do this once and I spent ten minutes, at most.
Upvotes: 0
Reputation: 872
The extension in the selected answer above only works in vs2012 while Code Maid works in vs2010 - vs2014:
There is a free extension called Code Maid that "is an open source Visual Studio extension to cleanup, dig through and simplify our C#, C++, F#, VB, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding." Does images as well.
Upvotes: 1
Reputation: 6547
There's a Visual Studio Extension that searches for unreferenced image files. It finds all image files in your project and then scan all aspx/cs/ashx/css/js files for references. It has not yet been updated for Visual Studio 2012.
http://visualstudiogallery.msdn.microsoft.com/fb7a9b9c-08e1-4bb4-91b4-8e512feb5a1b
Upvotes: 9
Reputation: 3164
Update You will not find a tool that can systematically identify unused resources, because JavaScript, CSS, and image files can be loaded dynamically. This article shows how to load JavaScript and CSS dynamically, and it's a straightforward task in JavaScript to load an image dynamically. It's easy to imagine a scenario in which the image name is loaded from an external data source, or concatenated from another field value plus ".jpg". Clearly any tool that attempted to scan your source to find unreferenced files would miss these resources.
That said, you can search for hard-coded references to .js, .css, and .jpg files using Visual Studio's search by regular expression feature, or by using a high-powered text editor like Notepad++ with a Regular Expression search feature.
For example, to use Visual Studio to search for all files ending in .js that are referenced in ASCX ir ASPX pages, go to Edit/Find and Replace/Find in Files, set the search expression to .js> switch on "Use Regular Expressions", and set "Look in these file types" to "*.aspx; *.ascx". ("\" escapes the ".", and ">" means end of word, so that "foo.js" is found, but not "foo.jsx". Visual Studio has its own Regular Expression syntax, which is documented here)
In addition, the tools in my original response below can give a good picture of what JS/CSS/IMAGE resources are actually getting used when your site is loaded. When used in conjunction with a testing tool like Selenium, these should allow you to remove resources with confidence.
There are several tools you should look at:
WARI scans your web application and examines dependencies between JavaScript functions, CSS styles, HTML tags and images.
The goal is to find unused images as well as unused and duplicated JavaScript functions and CSS styles.
Upvotes: 5