Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

CI 환경에서 Docker build 시 csproj의 Link 파일에 대한 빌드 오류

하나의 솔루션에 포함된 다중 프로젝트에서 소스 코드를 관리할 때, 가끔씩 공통 소스 코드는 하나의 프로젝트에 추가한 다음, 다른 프로젝트에서 LINK로 연결해서 쓰는 경우가 있습니다.

<ItemGroup>
    <Compile Include="..\test_prj\MyStruct.cs" Link="MyStruct.cs" />
</ItemGroup>

이게 CI 빌드 환경의 dockerfile에서는 이런 식의 오류가 발생하는군요. ^^

...[생략]...
Step 10/16 : RUN dotnet build "current_prj.csproj" -c Release -o /app/build
 ---> Running in ad1801f1a0fd
Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
  Determining projects to restore...
  All projects are up-to-date for restore.
CSC : error CS2001: Source file '/src/current_prj/../test_prj/MyStruct.cs' could not be found. [/src/current_prj/current_prj.csproj]
Build FAILED.
CSC : error CS2001: Source file '/src/current_prj/../test_prj/MyStruct.cs' could not be found. [/src/current_prj/current_prj.csproj]
    0 Warning(s)
    1 Error(s)
Time Elapsed 00:00:02.57
The command '/bin/sh -c dotnet build "current_prj.csproj" -c Release -o /app/build' returned a non-zero code: 1
Cleaning up project directory and file based variables

원래 프로젝트가 다음과 같은 구조인데,

./my/test_prj
./my/current_prj

./my/current_prj가 CI Build 디렉터리의 루트가 되는 상황에서 "COPY ../test_prj ./test_prj"와 같은 식으로 상위 my 디렉터리를 경유해 접근하고 싶어도 다음과 같은 식의 오류가 발생합니다.

Step 8/17 : COPY ./../test_prj ./test_prj
COPY failed: Forbidden path outside the build context: ../test_prj ()

어쩔 수 없습니다. 이 오류를 해결하고 싶다면, 2개의 프로젝트를 모두 포함하는 상위 디렉터리에서 CI 빌드 문맥을 시작해야 합니다.




또 다른 우회 방법으로는, 빌드 이벤트를 활용해 대상 파일을 미리 복사해 프로젝트에 포함하는 방법으로 처리를 해야 합니다.

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

  // ...[생략]...

  <Target Name="PreBuild" Condition="$(Configuration) == 'Debug'" BeforeTargets="PreBuildEvent">
    <Exec Command="robocopy ..\test_prj . MyStruct.cs&#xD;&#xA;exit 0" />
  </Target>

</Project>

저렇게 Debug 시에만 복사하도록 지정하고, 평소 로컬에서 개발 시 소스 코드가 부지런히 반영되도록 한 다음, 아래의 설정을 포함시키면,

  <ItemGroup Condition="$(Configuration) == 'Debug'">
    <Compile Include="..\test_prj\MyStruct.cs" Link="MyStruct.cs" />
    <Compile Remove="MyStruct.cs" />
  </ItemGroup>

Debug 상황에서만 LINK 경로의 파일을 사용하게 하고, CI 빌드 시에는 로컬 경로의 소스 코드를 참조하게 만드는 것입니다. 그런데, 사실 이미 robocopy로 로컬에 복사를 했기 때문에 저렇게 굳이 LINK 연결을 보존해야 할 필요는 없습니다. ^^;




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







[최초 등록일: ]
[최종 수정일: 3/2/2022]

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

비밀번호

댓글 작성자
 




... 61  62  63  64  65  66  67  68  69  70  [71]  72  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
12162정성태2/26/202021837디버깅 기술: 166. C#에서 만든 COM 객체를 C/C++로 P/Invoke Interop 시 메모리 누수(Memory Leak) 발생 [6]파일 다운로드2
12161정성태2/26/202017880오류 유형: 597. manifest - The value "x64" of attribute "processorArchitecture" in element "assemblyIdentity" is invalid.
12160정성태2/26/202018247개발 환경 구성: 469. Reg-free COM 개체 사용을 위한 manifest 파일 생성 도구 - COMRegFreeManifest
12159정성태2/26/202015356오류 유형: 596. Visual Studio - The project needs to include ATL support
12158정성태2/25/202017936디버깅 기술: 165. C# - Marshal.GetIUnknownForObject/GetIDispatchForObject 사용 시 메모리 누수(Memory Leak) 발생파일 다운로드1
12157정성태2/25/202017977디버깅 기술: 164. C# - Marshal.GetNativeVariantForObject 사용 시 메모리 누수(Memory Leak) 발생 및 해결 방법파일 다운로드1
12156정성태2/25/202016554오류 유형: 595. LINK : warning LNK4098: defaultlib 'nafxcw.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
12155정성태2/25/202016012오류 유형: 594. Warning NU1701 - This package may not be fully compatible with your project
12154정성태2/25/202015388오류 유형: 593. warning LNK4070: /OUT:... directive in .EXP differs from output filename
12153정성태2/23/202019507.NET Framework: 898. Trampoline을 이용한 후킹의 한계파일 다운로드1
12152정성태2/23/202018570.NET Framework: 897. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 - 세 번째 이야기(Trampoline 후킹)파일 다운로드1
12151정성태2/22/202019355.NET Framework: 896. C# - Win32 API를 Trampoline 기법을 이용해 C# 메서드로 가로채는 방법 - 두 번째 이야기 (원본 함수 호출)파일 다운로드1
12150정성태2/21/202019604.NET Framework: 895. C# - Win32 API를 Trampoline 기법을 이용해 C# 메서드로 가로채는 방법 [1]파일 다운로드1
12149정성태2/20/202018417.NET Framework: 894. eBEST C# XingAPI 래퍼 - 연속 조회 처리 방법 [1]
12148정성태2/19/202020942디버깅 기술: 163. x64 환경에서 구현하는 다양한 Trampoline 기법 [1]
12147정성태2/19/202018624디버깅 기술: 162. x86/x64의 기계어 코드 최대 길이
12146정성태2/18/202019371.NET Framework: 893. eBEST C# XingAPI 래퍼 - 로그인 처리파일 다운로드1
12145정성태2/18/202019233.NET Framework: 892. eBEST C# XingAPI 래퍼 - Sqlite 지원 추가파일 다운로드1
12144정성태2/13/202019423.NET Framework: 891. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 - 두 번째 이야기파일 다운로드1
12143정성태2/13/202015990.NET Framework: 890. 상황별 GetFunctionPointer 반환값 정리 - x64파일 다운로드1
12142정성태2/12/202018344.NET Framework: 889. C# 코드로 접근하는 MethodDesc, MethodTable파일 다운로드1
12141정성태2/10/202017380.NET Framework: 888. C# - ASP.NET Core 웹 응용 프로그램의 출력 가로채기 [2]파일 다운로드1
12140정성태2/10/202017920.NET Framework: 887. C# - ASP.NET 웹 응용 프로그램의 출력 가로채기파일 다운로드1
12139정성태2/9/202019183.NET Framework: 886. C# - Console 응용 프로그램에서 UI 스레드 구현 방법
12138정성태2/9/202023206.NET Framework: 885. C# - 닷넷 응용 프로그램에서 SQLite 사용 [6]파일 다운로드1
12137정성태2/9/202016431오류 유형: 592. [AhnLab] 경고 - 디버거 실행을 탐지했습니다.
... 61  62  63  64  65  66  67  68  69  70  [71]  72  73  74  75  ...