developer tip

Visual Studio, 솔루션 별 들여 쓰기 설정

copycodes 2020. 9. 19. 11:30
반응형

Visual Studio, 솔루션 별 들여 쓰기 설정


나는 몇 가지 다른 작업을하고 있으며 일부는 탭을 사용하고 일부는 들여 쓰기에 2 개의 공백을 사용하고 다른 사용자는 들여 쓰기에 4 개의 공백을 사용합니다.

Visual Studio에서이를 설정하는 옵션은 도구-> 옵션-> 텍스트 편집기-> <언어>-> 탭에 있습니다.

솔루션 기반에서 이러한 설정을 재정의하는 방법이 있습니까?


다음은 원하는 것을 달성하는 한 가지 방법입니다.

1) 들여 쓰기를 변경하는 매크로 만들기 ( 소스 )

 Sub Set-Indent(indent As integer)
     Dim props As EnvDTE.Properties = DTE.Properties("TextEditor", "C/C++")
     Dim ts As EnvDTE.Property = props.Item("TabSize")
     Dim ins As EnvDTE.Property = props.Item("IndentSize")
     ts.Value = indent 
     ins.Value = indent 
 End Sub

2) 솔루션로드와 연결 : 매크로 탐색기에서를 선택 하고 첫 번째 드롭 다운 에서 두 번째 드롭 다운을 EnvironmentEvents선택 합니다. 이제 솔루션을 열 때마다 트리거되는 매크로가 있습니다. 솔루션을 필요한 들여 쓰기에 매핑하기 만하면됩니다.SolutionEventsOpened


업데이트 : VS 2017은 기본적으로 EditorConfig를 지원합니다 : https://blogs.msdn.microsoft.com/dotnet/2016/12/15/code-style-configuration-in-the-vs2017-rc-update/

VS 2010 이상 에는 솔루션 / 프로젝트 루트의 .editorconfig 파일을 기반으로 들여 쓰기를 설정하는 확장이 있습니다 .

http://visualstudiogallery.msdn.microsoft.com/c8bccfe2-650c-4b42-bc5c-845e21f96328

Visual Studio Code에 대한 유사한 확장 도 있습니다 .


"Rebracer"라는 또 다른 추가 기능도 있습니다 ... 링크는 다음과 같습니다. http://visualstudiogallery.msdn.microsoft.com/410e9b9f-65f3-4495-b68e-15567e543c58


VS 확장 EditorConfig ( http://visualstudiogallery.msdn.microsoft.com/c8bccfe2-650c-4b42-bc5c-845e21f96328 ) 웹 사이트에서 :

EditorConfig 프로젝트는 들여 쓰기 크기와 같은 일반적인 텍스트 편집기 옵션을 구성하기위한 간단한 파일 형식을 정의 합니다 . 이러한 구성 파일은 프로젝트의 소스 코드와 함께 배치되도록 설계되어 텍스트 편집기가 파일별로 올바른 옵션을 사용할 수 있도록합니다. EditorConfig 프로젝트는 많은 일반 텍스트 편집 기용 플러그인을 제공하여 형식을 완전히 교차 플랫폼으로 만듭니다.

(강조 내)

전체 공개 : ReSharper가 인수했기 때문에 개인적으로 테스트 할 수 없었습니다.


VS2017 RC는 .editorconfig 형식에 대한 지원을 추가했습니다.


다음을 사용하여 탭 / 공백 삽입 설정을 지정할 수 있습니다. props.Item("InsertTabs") = bool

이것을 확인하십시오 : https://github.com/jamesfoster/VS-Whitespace-Macros


업데이트 : Resharper에서 들여 쓰기가 관리되지 않는 것처럼 보이 므로이 답변은 실제로 특정 질문을 해결하지 않습니다. 그러나 일반 용어로 적용됩니다. "Visual Studio, 솔루션 별 설정" 을 찾는 사람이 여기에서 우연히 발견되는 경우를 대비하여.


Resharper 를 사용 하는 경우 솔루션에 대한 서식 설정 (실제로 모든 설정)을 저장할 수 있습니다. 자신만을위한 것인지 (즉, 소스 제어에 전념하지 않음) 또는 공유 솔루션 별 설정 (즉, 소스 제어에 전념)을 지정할 수 있습니다.

Resharper > Options > Code Editing > C# (or whatever language) > Formatting Style > Braces Layout

그런 다음 창 하단의 Save To"Solution XYZ personal"(또는 목적에 따라 공유)을 선택합니다.

다음 YOURSOLUTION.sln.DotSettings.user과 같은 값을 가진 xml 파일이 생성 됩니다.

<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue">NEXT_LINE</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/CASE_BLOCK_BRACES/@EntryValue">NEXT_LINE</s:String>

Resharper 설정-솔루션 용으로 만 저장


그래서, 받아 들여진 솔루션은 "당신은 당신의 솔루션을 필요한 들여 쓰기에 매핑하기 만하면됩니다."라고 말합니다. 어떻게 하는지를 제외하고는 훌륭합니다. 그것을 알아 내기 위해 많은 시간을 낭비한 후 여기서 선호하는 방법을 찾았 습니다 . 이 방법은 모든 솔루션에 대해 다를 수있는 내 보낸 설정을 원하는만큼로드합니다. 설정에는 들여 쓰기부터 색상 또는 창 레이아웃까지 모든 것이 포함될 수 있습니다 (제 생각에).

  • Visual Studio 2008에서 도구> 매크로> 매크로 탐색기를 엽니 다.
  • MyMacros> Module1을 두 번 클릭합니다 (Module1이없는 경우 MyMacros를 마우스 오른쪽 단추로 클릭하고 '새 모듈 ...'을 선택하여 만듭니다).
  • 매크로 탐색기 창에서 왼쪽의 'EnvironmentEvents'를 두 번 클릭합니다.
  • 왼쪽 상단 드롭 다운에서 'SolutionEvents'를 선택합니다.
  • 오른쪽 상단 드롭 다운에서 '열림'을 선택합니다.
  • Code to handle the SolutionEvents.Opened event is automatically added. Change that code to the following:

    Private Sub SolutionEvents_Opened() Handles SolutionEvents.Opened
        Dim item As ProjectItem = DTE.Solution.FindProjectItem("solution.vssettings")
        If Not item Is Nothing Then
            'MsgBox("Uncomment this to see a message when settings are loaded")
            Dim name = item.FileNames(1)
            DTE.ExecuteCommand("Tools.ImportandExportSettings", "/import:""" & name & """")
        End If
    End Sub
    
  • Save the macro.

  • Use Tools > Options to change your UI to have the tab settings and whatever else you want set.
  • Tools > Import and Export Settings... > Export selected environment settings > Next
  • To just export tab settings, uncheck 'All Settings' then check Options > Text Editor > C/C++
  • Click Next, then type 'solution.vssettings' as 'What do you want to name your settings file?' and save the file to wherever you have a solution you want to use those settings.
  • Drag solution.vssettings to any location in the Solution Explorer window.
  • Quit Visual Studio and next time you open a solution containing solution.vssettings, it should load those settings.

If the macro doesn't run, it could be because of a MS security patch. Based on this, add the following string:

<AllowDComReflection enabled="true"/>

Below the <runtime> tag in the following three files:

"C:\Program Files (x86)\Common Files\Microsoft Shared\VSA\9.0\VsaEnv\vsmsvr.exe.config"
"C:\Program Files (x86)\Common Files\Microsoft Shared\VSA\9.0\VsaEnv\vsaenv.exe.config"
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe.config"

Be sure to start the editor you use to edit those files with Administrator privileges (ie right click Notepad and choose 'Run as Administrator').

I also found a plug-in that's supposed to do the same thing as the macro suggested above but for some reason it didn't do anything after I ran its installer.


clang-format provides quite sophisticated options for formatting your source code.

The Visual Studio plugin is quite rudimentary, i.e. it does not run automatically, but it does its job well (when manually invoked, that is).

http://llvm.org/builds/

참고 URL : https://stackoverflow.com/questions/1212092/visual-studio-per-solution-indentation-settings

반응형