Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
(연관된 글이 1개 있습니다.)
(시리즈 글이 10개 있습니다.)
VS.NET IDE: 60. Output 경로에 매크로 상수 사용하는 방법
; https://www.sysnet.pe.kr/2/0/688

개발 환경 구성: 91. MSBuild를 이용한 닷넷 응용프로그램의 플랫폼(x86/x64)별 빌드
; https://www.sysnet.pe.kr/2/0/963

개발 환경 구성: 93. MSBuild를 이용한 닷넷 응용프로그램의 다중 어셈블리 출력 빌드
; https://www.sysnet.pe.kr/2/0/965

개발 환경 구성: 102. MSBuild - DefineConstants에 다중 전처리 값 설정
; https://www.sysnet.pe.kr/2/0/988

개발 환경 구성: 115. MSBuild - x86/x64, .NET 2/4, debug/release 빌드에 대한 배치 처리
; https://www.sysnet.pe.kr/2/0/1017

개발 환경 구성: 372. MSBuild - 빌드 전/후, 배포 전/후 실행하고 싶은 Task 정의
; https://www.sysnet.pe.kr/2/0/11507

개발 환경 구성: 452. msbuild - csproj에 환경 변수 조건 사용
; https://www.sysnet.pe.kr/2/0/11985

개발 환경 구성: 580. msbuild의 Exec Task에 robocopy를 사용하는 방법
; https://www.sysnet.pe.kr/2/0/12716

개발 환경 구성: 693. msbuild - .NET Core/5+ 프로젝트에서 resgen을 이용한 리소스 파일 생성 방법
; https://www.sysnet.pe.kr/2/0/13481

닷넷: 2235. MSBuild - AccelerateBuildsInVisualStudio 옵션
; https://www.sysnet.pe.kr/2/0/13593




MSBuild를 이용한 닷넷 응용프로그램의 다중 어셈블리 출력 빌드

우선, 다음의 글을 읽고 나서 이번 글을 보시길 바랍니다.

MSBuild를 이용한 닷넷 응용프로그램의 플랫폼(x86/x64) 별 빌드
; https://www.sysnet.pe.kr/2/0/963

종종 개발을 하다 보면, 플랫폼만 구분단위가 되지는 않습니다. 가령 .NET 응용 프로그램을 만드는 중에 흔한 경우가 있다면 특정 버전의 .NET Framework이 설치된 경우에 따라 어셈블리 생성을 달리해야 할 수 가 있습니다.

대개, 그런 경우 전처리기를 사용하게 되는데, 대략 아래와 같이 되겠지요.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        this.Text += ": " + ((IntPtr.Size == 4) ? "x86" : "x64");

#if ISNET35
        MessageBox.Show(".NET 3.5");
#endif
    }
}

그런 다음, 2가지 버전이 한꺼번에 빌드될 수 있도록, 스크립트를 다음과 같이 변경해 주어야 합니다.

FOR /F %%I IN ("%0") DO SET CURRENTDIR=%%~dpI
SET SOLUTIONDIR=%CURRENTDIR%

msbuild MyTest.csproj /property:MyAssemblyName=MyTest32.Clr20;PlatformTarget=x86;Platform=x86;SolutionDir=%SOLUTIONDIR%
msbuild MyTest.csproj /property:MyAssemblyName=MyTest32.Clr35;DefineConstants=ISNET35;PlatformTarget=x86;Platform=x86;SolutionDir=%SOLUTIONDIR%

하지만, 기대했던 결과와는 달리 아래와 같이 대상 폴더에는 MyTest32.Clr20.exe 파일이 보이지 않습니다.

.\bin\Debug\MyTest32.Clr35.exe
            MyTest32.Clr35.pdb

도대체 이유가 뭘까요?

명령행에서 MSBuild를 해보면 다음과 같이 "IncrementalClean" 단계에서 이전에 했던 msbuild 결과물들을 모두 삭제하는 것을 확인할 수 있습니다.

IncrementalClean:
  Deleting file "D:\...\obj\x86\Debug\MyTest32.Clr20.exe".
  Deleting file "D:\...\obj\x86\Debug\MyTest32.Clr20.pdb".
  Deleting file "D:\...\bin\Debug\MyTest32.Clr20.exe".
  Deleting file "D:\...\bin\Debug\MyTest32.Clr20.pdb".

오~~~ 쪼끔 신기합니다. ^^ 도대체 이전에 빌드했던 DLL들의 파일명을 어떻게 일일이 기억하고 저렇게 싸~~~악 지워버리는지?
검색을 좀 해본 결과 아래의 글에 힌트가 있더군요.

MSBuild is not copying the assembly to the output directory.
; http://social.msdn.microsoft.com/forums/en-US/msbuild/thread/ae00d3f7-a1c4-4378-96b6-9a4099c74b2a/

즉, msbuild는 빌드를 할 때마다 ".\obj\[platform]\Debug\MyTest32.csproj.FileListAbsolute.txt"와 같이 "FileListAbsolute.txt" 확장자를 가진 파일에 해당 빌드가 이뤄지는 동안 생성된 파일들의 목록을 기록해 둡니다. 그리고, 다음번 빌드가 수행될 때 "FileListAbsolute.txt" 파일에 있는 모든 파일을 삭제하고 새롭게 빌드를 해주는 것입니다.

검색을 좀 더 해보았으나, 마이크로소프프트에서 공식적으로 권장하는 MSBuild 옵션은 찾을 수 없었습니다. 위의 글에서 나온 것처럼 수작업으로 "FileListAbsolute.txt" 파일을 지워주는 것이 최선인데요. 그래서 빌드 스크립트를 다음과 같이 변경해주어야 합니다.

FOR /F %%I IN ("%0") DO SET CURRENTDIR=%%~dpI
SET SOLUTIONDIR=%CURRENTDIR%

msbuild MyTest.csproj /property:MyAssemblyName=MyTest32.Clr20;PlatformTarget=x86;Platform=x86;SolutionDir=%SOLUTIONDIR%
del .\*.FileListAbsolute.txt /s
msbuild MyTest.csproj /property:MyAssemblyName=MyTest32.Clr35;DefineConstants=ISNET35;PlatformTarget=x86;Platform=x86;SolutionDir=%SOLUTIONDIR%

솔직히, 어쩔 수 없이 위와 같이 처리를 하긴 했지만 왠지 개운하지 않은 느낌이 듭니다. 혹시 좀 더 좋은 방법을 제시해주시는 분이 있을까요? ^^

* 첨부한 파일은 위의 빌드 스크립트가 포함된 예제입니다.



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

[연관 글]






[최초 등록일: ]
[최종 수정일: 7/10/2021]

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

비밀번호

댓글 작성자
 




... 46  47  48  49  50  51  52  53  54  55  56  57  58  59  [60]  ...
NoWriterDateCnt.TitleFile(s)
12438정성태12/2/202017786오류 유형: 688. .Visual C++ - Error C2011 'sockaddr': 'struct' type redefinition
12437정성태12/1/202017997VS.NET IDE: 155. pfx의 암호 키 파일을 Visual Studio 없이 등록하는 방법
12436정성태12/1/202018150오류 유형: 687. .NET Core 2.2 빌드 - error MSB4018: The "RazorTagHelper" task failed unexpectedly.
12435정성태12/1/202025238Windows: 181. 윈도우 환경에서 클라이언트 소켓의 최대 접속 수 (4) - ReuseUnicastPort를 이용한 포트 고갈 문제 해결 [1]파일 다운로드1
12434정성태11/30/202019072Windows: 180. C# - dynamicport 값의 범위를 알아내는 방법
12433정성태11/29/202017779Windows: 179. 윈도우 환경에서 클라이언트 소켓의 최대 접속 수 (3) - SO_PORT_SCALABILITY파일 다운로드1
12432정성태11/29/202019299Windows: 178. 윈도우 환경에서 클라이언트 소켓의 최대 접속 수 (2) - SO_REUSEADDR [1]파일 다운로드1
12431정성태11/27/202016126.NET Framework: 976. UnmanagedCallersOnly + C# 9.0 함수 포인터 사용 시 x86 빌드에서 오동작하는 문제파일 다운로드1
12430정성태11/27/202018564오류 유형: 686. Ubuntu - E: The repository 'cdrom://...' does not have a Release file.
12429정성태11/25/202018648디버깅 기술: 175. windbg - 특정 Win32 API에서 BP가 안 걸리는 경우
12428정성태11/25/202016787VS.NET IDE: 154. Visual Studio - .NET Core App 실행 시 dotnet.exe 실행 화면만 나오는 문제
12427정성태11/24/202017626.NET Framework: 975. .NET Core를 직접 호스팅해 (runtimeconfig.json 없이) EXE만 배포해 실행파일 다운로드1
12426정성태11/24/202016007오류 유형: 685. WinDbg Preview - error InitTypeRead
12425정성태11/24/202017669VC++: 141. Visual C++ - "Treat Warnings As Errors" 옵션이 꺼져 있는데도 일부 경고가 에러 처리되는 경우
12424정성태11/24/202017976VC++: 140. C++의 연산자 동의어(operator synonyms), 대체 토큰 [1]
12423정성태11/22/202018611.NET Framework: 974. C# 9.0 - (16) 제약 조건이 없는 형식 매개변수 주석(Unconstrained type parameter annotations)파일 다운로드1
12422정성태11/21/202016022.NET Framework: 973. .NET 5, .NET Framework에서만 허용하는 UnmanagedCallersOnly 사용예파일 다운로드1
12421정성태11/19/202015316.NET Framework: 972. DNNE가 출력한 NE DLL을 직접 생성하는 방법파일 다운로드1
12420정성태11/19/202015260오류 유형: 684. Visual C++ - MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
12419정성태11/19/202016130VC++: 139. Visual C++ - .NET Core의 nethost.lib와 정적 링크파일 다운로드1
12418정성태11/19/202018380오류 유형: 683. Visual C++ - error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug'파일 다운로드1
12417정성태11/19/202016112오류 유형: 682. Visual C++ - warning LNK4099: PDB '...pdb' was not found with '...lib(pch.obj)' or at '...pdb'; linking object as if no debug info
12416정성태11/19/202017207오류 유형: 681. Visual C++ - error LNK2001: unresolved external symbol _CrtDbgReport
12415정성태11/18/202017423.NET Framework: 971. UnmanagedCallersOnly 특성과 DNNE 사용파일 다운로드1
12414정성태11/18/202019582VC++: 138. x64 빌드에서 extern "C"가 아닌 경우 ___cdecl name mangling 적용 [4]파일 다운로드1
12413정성태11/17/202018544.NET Framework: 970. .NET 5 / .NET Core - UnmanagedCallersOnly 특성을 사용한 함수 내보내기파일 다운로드1
... 46  47  48  49  50  51  52  53  54  55  56  57  58  59  [60]  ...