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

비밀번호

댓글 작성자
 




... 31  32  33  34  35  36  [37]  38  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
13014정성태3/23/202215059VC++: 155. CComPtr/CComQIPtr과 Conformance mode 옵션의 충돌 [1]
13013정성태3/22/202212856개발 환경 구성: 641. WSL 우분투 인스턴스에 파이썬 2.7 개발 환경 구성하는 방법
13012정성태3/21/202212494오류 유형: 803. C# - Local '...' or its members cannot have their address taken and be used inside an anonymous method or lambda expression
13011정성태3/21/202215988오류 유형: 802. 윈도우 운영체제에서 웹캠 카메라 인식이 안 되는 경우
13010정성태3/21/202212702오류 유형: 801. Oracle.ManagedDataAccess.Core - GetTypes 호출 시 "Could not load file or assembly 'System.DirectoryServices.Protocols...'" 오류
13009정성태3/20/202215304개발 환경 구성: 640. docker - ibmcom/db2 컨테이너 실행
13008정성태3/19/202214897VS.NET IDE: 176. 비주얼 스튜디오 - 솔루션 탐색기에서 프로젝트를 선택할 때 csproj 파일이 열리지 않도록 만드는 방법
13007정성태3/18/202213285.NET Framework: 1181. C# - Oracle.ManagedDataAccess의 Pool 및 그것의 연결 개체 수를 알아내는 방법파일 다운로드1
13006정성태3/17/202215687.NET Framework: 1180. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 remuxing.c 예제 포팅
13005정성태3/17/202213970오류 유형: 800. C# - System.InvalidOperationException: Late bound operations cannot be performed on fields with types for which Type.ContainsGenericParameters is true.
13004정성태3/16/202213483디버깅 기술: 182. windbg - 닷넷 메모리 덤프에서 AppDomain에 걸친 정적(static) 필드 값을 조사하는 방법
13003정성태3/15/202213819.NET Framework: 1179. C# - (.NET Framework를 위한) Oracle.ManagedDataAccess 패키지의 성능 카운터 설정 방법
13002정성태3/14/202215401.NET Framework: 1178. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 http_multiclient.c 예제 포팅
13001정성태3/13/202216009.NET Framework: 1177. C# - 닷넷에서 허용하는 메서드의 매개변수와 호출 인자의 최대 수
13000정성태3/12/202214969.NET Framework: 1176. C# - Oracle.ManagedDataAccess.Core의 성능 카운터 설정 방법
12999정성태3/10/202214804.NET Framework: 1175. Visual Studio - 프로젝트 또는 솔루션의 Clean 작업 시 응용 프로그램에서 생성한 파일을 함께 삭제파일 다운로드1
12998정성태3/10/202213216.NET Framework: 1174. C# - ELEMENT_TYPE_FNPTR 유형의 사용 예
12997정성태3/10/202222321오류 유형: 799. Oracle.ManagedDataAccess - "ORA-01882: timezone region not found" 오류가 발생하는 이유
12996정성태3/9/202223758VS.NET IDE: 175. Visual Studio - 인텔리센스에서 오버로드 메서드를 키보드로 선택하는 방법
12995정성태3/8/202216119.NET Framework: 1173. .NET에서 Producer/Consumer를 구현한 BlockingCollection<T>
12994정성태3/8/202215186오류 유형: 798. WinDbg - Failed to load data access module, 0x80004002
12993정성태3/4/202214909.NET Framework: 1172. .NET에서 Producer/Consumer를 구현하는 기초 인터페이스 - IProducerConsumerCollection<T>
12992정성태3/3/202217874.NET Framework: 1171. C# - BouncyCastle을 사용한 암호화/복호화 예제파일 다운로드1
12991정성태3/2/202215667.NET Framework: 1170. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 transcode_aac.c 예제 포팅
12990정성태3/2/202215792오류 유형: 797. msbuild - The BaseOutputPath/OutputPath property is not set for project '[...].vcxproj'
12989정성태3/2/202213786오류 유형: 796. mstest.exe - System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.QualityTools.Tips.WebLoadTest.Tip
... 31  32  33  34  35  36  [37]  38  39  40  41  42  43  44  45  ...