Unused usings

Having Obsessive-Compulsive tendencies, I spent some time stripping unused Usings from our .cs files, all 626 of them. Smug with my efforts, I then wondered if it had achieved anything useful, specifically if it had reduced the size of our generated dlls. I was a little dissapointed to discover that it had not but OTOH it seems that I probably improved the compile time of the app a little bit.

This post by Andrew Troelsen of the MSDN C# Team says that the C# compiler, csc.exe, ignores Usings and Assembly References not referenced in code, while under the Comments in the same post Anthony Ashe points out that the compiler still does a ‘copy local’ for unused assemblies leading to redundant crud lying around in your bin directories as well as your source code.

In addition to the above, as Patricia Shanahan points out, it is good practice to remove Unused Usings as inspection of your Usings helps to convey to maintainers of your code what your code is likely to do and affect.

Now, if you’ll excuse me, its time to Dettol the cat.

Advertisements

Tags: ,

2 Responses to “Unused usings”

  1. Neal Says:

    “while under the Comments in the same post Anthony Ashe points out that the compiler still does a ‘copy local’ for unused assemblies leading to redundant crud lying around in your bin directories as well as your source code.”

    In my company its general practice that as soon as we add a reference… in the property menu of that assembly we set false to “Copy Local” thus it wont copy any of the DLL to your local bin folder…

  2. peppiness Says:

    peppiness says : I absolutely agree with this !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: