<p>As I get more and more namespaces in my solution, the list of using statements at the top of my files grows longer and longer.  This is especially the case in my unit tests where for each component that might be called I need to include the using for the interface, the IoC container, and the concrete type.  </p>

<p>With upward of 17 lines of usings in my integration test files its just getting downright messy.  Does anyone know if theres a way to define a macro for my base using statements?  Any other solutions?</p>

[{'answer_id': 62223, 'author': 'Rikalous', 'author_id': 4271, 'author_profile': 'https://Stackoverflow.com/users/4271', 'pm_score': 0, 'selected': False, 'text': "<p>Resharper  - the add-in for Visual Studio - has a feature that strips unsued Using's from a file, but I don't know anything that does quite what you describe.</p>\n"}, {'answer_id': 62224, 'author': 'Blair Conrad', 'author_id': 1199, 'author_profile': 'https://Stackoverflow.com/users/1199', 'pm_score': 3, 'selected': True, 'text': "<p>Some people enjoy hiding the usings in a <code>#region</code>. Otherwise, I think you're out of luck. Unless you want to put the namespace on all your referents.</p>\n"}, {'answer_id': 62253, 'author': 'Roger Ween', 'author_id': 6143, 'author_profile': 'https://Stackoverflow.com/users/6143', 'pm_score': 1, 'selected': False, 'text': "<blockquote>\n  <p>Does anyone know if theres a way to\n  define a macro for my base using\n  statements?</p>\n</blockquote>\n\n<p>Do you mean that namespaces you use often are automaticly added to each new class? If yes, Resharper can do that too. Additionaly it has a feature to put the usings in a region on code clean-up. Resharper may be the way to go (you won't regrett it as I can say from my own experience).</p>\n"}, {'answer_id': 62270, 'author': 'Bjorn Reppen', 'author_id': 1324220, 'author_profile': 'https://Stackoverflow.com/users/1324220', 'pm_score': 3, 'selected': False, 'text': "<p>I know I shouldn't say this out loud, but, maybe reconsider your design.</p>\n\n<p>17 usings in 1 file = a lot of coupling (on the namespace level).</p>\n"}, {'answer_id': 62296, 'author': 'Kent Boogaart', 'author_id': 5380, 'author_profile': 'https://Stackoverflow.com/users/5380', 'pm_score': 2, 'selected': False, 'text': '<p>Can\'t stand Resharper myself. But I also can\'t stand messy using statements. I use the <a href="http://code.msdn.microsoft.com/PowerCommands" rel="nofollow noreferrer">Power Commands</a> add-in for VS, which has a handy \'Remove and Sort\' using statements command (among other good things).</p>\n'}, {'answer_id': 62313, 'author': 'Scott Dorman', 'author_id': 1559, 'author_profile': 'https://Stackoverflow.com/users/1559', 'pm_score': 1, 'selected': False, 'text': '<p>VS2008 added an "Organize Usings" context menu, which has a Sort, Remove, and "Remove and Sort" option which will do what you want per file. The Visual Studio Power Commands add-in adds a context menu in the solution explorer for projects and solutions which is a "Remove and Sort" for all files in the project and all projects in the solution, respectively.</p>\n'}, {'answer_id': 62325, 'author': 'Mike Becatti', 'author_id': 6617, 'author_profile': 'https://Stackoverflow.com/users/6617', 'pm_score': 0, 'selected': False, 'text': "<p>In VS2008, you can right click on the CS file and choose 'Organize Usings'.  It will strip unused using and sort them for you too.  Other than that, I would just use #region.  Also, <kbd>CTRL</kbd>+<kbd>M</kbd>+<kbd>O</kbd> will collapse all your regions functions, etc at design time.  I use this shortcut A LOT!</p>\n"}, {'answer_id': 62355, 'author': 'Matthew Steeples', 'author_id': 6713, 'author_profile': 'https://Stackoverflow.com/users/6713', 'pm_score': 1, 'selected': False, 'text': '<p>If you want to change the default using statements that are done when you create a new file, take a look in the C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE\\ItemTemplates\\CSharp\\Code\\1033 directory. It contains a bunch of zip files that you can modify to change the templates for Code files (Obviously move up the directory structure to change other languages or other types of files).</p>\n\n<p>See <a href="http://mark.michaelis.net/Blog/ChangingTheDefaultItemTemplatesInVisualStudio2005.aspx" rel="nofollow noreferrer">here</a> for more information.</p>\n'}, {'answer_id': 62453, 'author': 'Steve Cooper', 'author_id': 6722, 'author_profile': 'https://Stackoverflow.com/users/6722', 'pm_score': 2, 'selected': False, 'text': "<p>There are four possible problems here;</p>\n\n<p><strong>The namespaces in your code are dividing your classes too finely.</strong> if you have, for example;</p>\n\n<pre><code>using MyCompany.Drawing.Vector.Points;\nusing MyCompany.Drawing.Vector.Shapes;\nusing MyCompany.Drawing.Vector.Transformations;\n</code></pre>\n\n<p>consider collapsing them to the single <code>MyCompany.Drawing.Vector</code> namespace. You probably aren't gaining by dividing too much. Visual Studio Code Analysis/FxCop has a rule for this, checking the number of classes in a namespace. Too few and it will warn you.</p>\n\n<p><strong>You are putting too many tests into the same class.</strong> If you are referencing <code>System.Data</code>, <code>System.Drawing</code>, and <code>System.IO</code> in the same class, consider writing more atomic tests -- some which access databases, some which draw images, and some which access the file system. Then divide each type across three test classes.</p>\n\n<p><strong>You are writing tests which do too much.</strong> If you are referencing a lot of namespaces, your tests may be coupling too many features together. This kind of coupling can often be buggy, so try to break big, wide-ranging functions into smaller parts, and test these in seperate files. </p>\n\n<p><strong>Many are redundant.</strong> Are they all used, or are they just copy-pasted from other files. Right-click on the code editor and choose from the 'Organise Using' options to remove unused statements.</p>\n"}, {'answer_id': 62717, 'author': 'Eugene Katz', 'author_id': 1533, 'author_profile': 'https://Stackoverflow.com/users/1533', 'pm_score': 1, 'selected': False, 'text': "<p>It may help to use aliasing.  Not sure it it's worth it, but instead of:</p>\n\n<pre><code>using System.Web.UI;\nusing System.Web.Mail;\nusing System.Web.Security;\n... Control ...\n... MailMessage ...\n... Roles ... \n</code></pre>\n\n<p>you can use:</p>\n\n<pre><code>using W = System.Web;\n... W.UI.Control ...\n... W.Mail.MailMessage ...\n... W.Security.Rolse ...\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/62219', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5056/']