How do i automate adding a “using” statement to every files in a folder, namespace or project with Visual Studio 2005 / resharper

后端 未结 4 1636
庸人自扰
庸人自扰 2021-01-17 19:00

I am using resharper to do a big refactoring and i keep going from file to file and adding the same namespace over and over again in the \"using\" section

is there a

4条回答
  •  爱一瞬间的悲伤
    2021-01-17 19:44

    I'd try a regex in the "Find and Replace" dialog:

    Replace

    ^using System;$
    

    with

    using System;\nusing xxx;
    

    This works only for files using the System namespace, but maybe you find another common namespace or structure element. After doing so you can refactor all files in your solution(/folder) with the resharper. That will remove doubled usings.

    Update: Did you introduce new namespaces for existing types? There is a refactor function called "move". It will move your type to a new namespace and preserve the references.

提交回复
热议问题