it-source

How to remove unused using namespaces

criticalcode 2023. 6. 25. 20:10
반응형

How to remove unused using namespaces

I am using visual studio 2010 and was wondering if there is a way to automatically remove all the namespaces that aren't being used at the the top of the page e.g.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

in the above example System.Collections.Generic is not being used is there a way to know that without trial and error.

Yes you can right click on the page and from the menu select;

Organise Usings > Remove Unused Usings

Alternatively if you prefer shortcuts, please use;

Ctrl + R + G

I am using this all the time, to clean up code, and make code compilation quicker.

Or you can use PowerCommands to remove unused usings for entire projects

Visual Studio 2017에서 저는 매우 간단한 키 조합을 사용합니다:RG ++를 사용하지 않은 키 제거imports/namespaces

Update:

In VS for Mac:

Unfortunately, there's no default key binding for this but you can always edit your preferences.

Visual Studio->Preferences

enter image description here 제 경우에는 ++RG로 바인딩되어 있습니다.

Microsoft에서 Productivity Power Tools 2015라는 확장명을 설치할 수 있으며 파일을 저장할 때 사용하지 않는 사용을 자동으로 제거하는 옵션이 있습니다.이후에 더 이상의 작업이 필요하지 않습니다.

enter image description here

enter image description here

Visual Studio 2019를 사용하는 경우 다음을 수행할 수 있습니다.

솔루션 -> 분석 코드 정리 -> 코드 정리 구성 -> 프로파일 생성(제거 및 정렬 사용)에서 마우스 오른쪽 단추를 누른실행합니다.

enter image description here enter image description here

VS 2019, VS 2022 또는 ReSharper의 경우.다음과 같은 파일의 맨 위에 사용하지 않는 사용을 추가하는 경우using System.IO;전구가 나타납니다.전구를 클릭하면 파일, 폴더, 프로젝트 또는 전체 솔루션에서 사용하지 않는 사용을 제거할 수 있습니다.

enter image description here

enter image description here

다른 사람들과 같은 대답.키보드 ShiftF10닌자(+ 상황별 메뉴 팝업)인 경우 다음을 사용합니다.

Shift+F10,O,R


상황에 맞는 메뉴를 위한 특수 키를 뭐라고 합니까?+(키보드에 해당 특수 키가 없기 때문에 F10+를 사용함)F10를 누르는 대신 다음 키를 짧게 누릅니다.

whateverThatKeyCalled, O, R

업데이트:

VS 2019 이상의 경우 더 나은 답변이 있습니다. Visual Studio 2019 이상의 경우를 참조하십시오. 이 질문은 다시 질문되었습니다.Visual Studio 2019에서 형식 문서에서 사용되지 않는 사용을 제거하려면 어떻게 해야 합니까?

원본 답변:

VS 2010에 명시된 OP를 알고 있지만, 그것은 오래 전이었고 이 기능은 VS 2017에 바로 내장되어 있습니다.메뉴, 도구 -> 옵션에서 아래 확인란을 찾습니다.

그런 다음 +, +를 사용하면 언제든지 제거됩니다.

Remove unnecessary usings

저는 Visual Studio 2019를 사용하고 있는데 어떤 이유에서인지 프로젝트 설정에 경고 수준이 3으로 표시되어 Visual Studio에서 사용을 정리할 수 없습니다.이 값이 4로 설정되어 있는지 확인합니다.

Settings -> Build -> Warning Level = 4

Asaj는 당신이 그것을 사용할 수 있다고 말하고 있습니다.Remove Unused Usings사용법을 동시에 정렬하면 훨씬 더 효과적입니다.Resharper 4.5는 VS2010에서 누락되거나 누락된 기능인 전체 프로젝트에 대해 이 작업을 수행할 수 있도록 지원합니다.

자세한 내용은 다음 스레드에서 제공됩니다.전체 어셈블리에서 사용되지 않는 사용 제거


팁: 위 스레드는 전체 솔루션에서 사용되지 않는 사용을 제거하기 위해 매크로를 제안하는 블로그를 참조합니다.전체 솔루션에서 사용 방법을 구성할 수 있습니다.방금 시험해 봤는데, 아주 잘 됐어요!

언급URL : https://stackoverflow.com/questions/12075909/how-to-remove-unused-using-namespaces

반응형