Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)
(시리즈 글이 2개 있습니다.)
개발 환경 구성: 131. Visual Studio - ASP.NET의 Code-behind처럼 cs 파일을 그룹핑하는 매크로 함수
; https://www.sysnet.pe.kr/2/0/1136

VS.NET IDE: 196. Visual Studio - Code-behind처럼 cs 파일을 그룹핑하는 방법
; https://www.sysnet.pe.kr/2/0/13886




Visual Studio - Code-behind처럼 cs 파일을 그룹핑하는 방법

예전에 이에 대한 설명을 한 적이 있는데요,

Visual Studio - ASP.NET의 Code-behind처럼 cs 파일을 그룹핑하는 매크로 함수
; https://www.sysnet.pe.kr/2/0/1136

결국 csproj 파일의 "DependentUpon" 노드를 이용하는 건데, 어느 버전부터인지는 알 수 없으나 비주얼 스튜디오가 더 쉬운 방법을 제공하고 있었습니다.

이에 대한 규칙이 단순한데요, 연관시키고 싶은 파일명과 동일한 이름으로 ".cs" 파일을 붙여주면 됩니다.

예를 들어, blazor 페이지인 "Counter.razor" 파일이 있다면, 이에 대응하는 코드 파일은 "Counter.razor.cs" 파일로 만들어 주면 됩니다. 아래는 C# 코드 파일을 "Counter.cs"로 준 경우에 비주얼 스튜디오가 보여주는 모습이고,

vs_codebehind_1.png

이제 해당 코드 파일을 "Counter.razor.cs"로 이름 변경만 해주면, 비주얼 스튜디오가 자동으로 이를 인식해 razor 파일 밑으로 코드 파일을 그룹핑해 줍니다.

vs_codebehind_2.png




그래도 DependentUpon을 이용한 방법은 여전히 유효합니다. 왜냐하면, 일반적인 코드 파일, 예를 들어 Program.cs인 경우 그에 더해 Program.cs.cs라고 새로운 파일을 추가해도 이번에는 그룹핑하지 않습니다.

따라서 그런 경우라면 DependentUpon을 이용해 강제로 파일을 그룹핑할 수 있습니다.

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>

    <ItemGroup>
        <Compile Include="Program.cs" />
        <Compile Include="Program.cs.cs">
            <DependentUpon>Program.cs</DependentUpon>
        </Compile>
    </ItemGroup>
</Project>

물론, 위와 같은 경우라면 굳이 Program.cs.cs와 같은 식으로 파일명을 짓기보다는 중간 이름을 좀 더 의미 있는 이름으로 짓는 것이 좋을 것입니다. (예를 들어, Program.dac.cs)




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 2/15/2025]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 151  152  153  154  [155]  156  157  158  159  160  161  162  163  164  165  ...
NoWriterDateCnt.TitleFile(s)
1177정성태11/18/201130003.NET Framework: 272. 소켓 연결 시간 제한 - 두 번째 이야기 [1]파일 다운로드1
1176정성태11/17/201129266.NET Framework: 271. C#에서 확인해 보는 관리 힙의 인스턴스 구조 [3]파일 다운로드1
1175정성태11/16/201127237.NET Framework: 270. .NET 참조 개체 인스턴스의 Object Header를 확인하는 방법 [1]파일 다운로드1
1174정성태11/15/201126621.NET Framework: 269. 일반 참조형의 기본 메모리 소비는 얼마나 될까요? [4]
1173정성태11/14/201122811.NET Framework: 268. .NET Array는 왜 12bytes의 기본 메모리를 점유할까? [1]
1172정성태11/13/201119821.NET Framework: 267. windbg - GC Heap에서 .NET 타입에 대한 배열을 찾는 방법
1171정성태11/12/201136502.NET Framework: 266. StringBuilder에서의 OutOfMemoryException 오류 원인 분석 [4]파일 다운로드1
1170정성태11/10/201125731.NET Framework: 265. Named 동기화 개체 생성 시 System.UnauthorizedAccessException 예외 발생하는 경우
1169정성태11/10/201129479.NET Framework: 264. 다중 LAN 카드 환경에서 Dns.GetHostAddresses(local)가 반환해 주는 IP의 우선순위는 어떻게 될까요? [4]
1168정성태11/6/201125343오류 유형: 139. TlbImp : error TI0000 : A single valid machine type compatible with the input type library must be specified
1167정성태11/5/201137141개발 환경 구성: 133. Registry 등록 과정 없이 COM 개체 사용 - 두 번째 이야기 [5]파일 다운로드4
1166정성태11/5/201123226.NET Framework: 263. byte[] pData = new byte[100000]로 인한 성능 차이? [1]파일 다운로드1
1165정성태11/3/201128115개발 환경 구성: 132. "Visual Studio Command Prompt (2010)" 명령행에서 2.0 버전의 MSBuild를 구동하는 방법 [2]파일 다운로드1
1164정성태11/1/201126310.NET Framework: 262. .NET 스레드 콜 스택 덤프 (4) - .NET 4.0을 지원하지 않는 MSE 응용 프로그램 원인 분석
1163정성태10/31/201125807.NET Framework: 261. .NET 스레드 콜 스택 덤프 (3) - MSE 소스 코드 개선파일 다운로드1
1162정성태10/30/201125892.NET Framework: 260. .NET 스레드 콜 스택 덤프 (2) - Managed Stack Explorer 소스 코드를 이용한 스택 덤프 구하는 방법파일 다운로드1
1161정성태10/29/201122751.NET Framework: 259. Type.GetMethod - System.Reflection.AmbiguousMatchException파일 다운로드1
1159정성태10/28/201126175.NET Framework: 258. Roslyn 맛보기 - SyntaxTree 조작 [2]
1158정성태10/24/201125487.NET Framework: 257. Roslyn 맛보기 - Roslyn Symbol / Binding API파일 다운로드1
1157정성태10/23/201129899.NET Framework: 256. Roslyn 맛보기 - Syntax Analysis (Roslyn Syntax API) [2]
1156정성태10/23/201128431.NET Framework: 255. Roslyn 맛보기 - Roslyn Services APIs를 이용한 Code Issue 및 Code Action 기능 소개 [1]
1155정성태10/22/201126459.NET Framework: 254. Roslyn 맛보기 - C# Interactive (2)
1154정성태10/22/201133205.NET Framework: 253. Roslyn 맛보기 - C# Interactive (1)
1153정성태10/21/201142070.NET Framework: 252. Roslyn 맛보기 - C# 소스 코드를 스크립트처럼 다루는 방법 [7]파일 다운로드1
1152정성태10/20/201123736.NET Framework: 251. string.GetHashCode는 hash 값을 cache 할까?
1151정성태10/18/201122659Java: 13. 자바도 64비트에서 (2GB) OutOfMemoryException 예외가 발생할까?
... 151  152  153  154  [155]  156  157  158  159  160  161  162  163  164  165  ...