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

비밀번호

댓글 작성자
 




... 106  107  108  109  110  111  112  113  114  [115]  116  117  118  119  120  ...
NoWriterDateCnt.TitleFile(s)
11049정성태9/24/201620933오류 유형: 357. 윈도우 백업 시 오류 - 0x81000037
11048정성태9/24/201621957VC++: 100. 전역 변수 유형별 실행 파일 크기 차이점
11047정성태9/21/201625785기타: 61. algospot.com - 양자화(Quantization) 문제 [2]파일 다운로드1
11046정성태9/15/201627414개발 환경 구성: 298. Windows 10 - bash 실행 시 시작 디렉터리 자동 변경
11045정성태9/15/201620083Windows: 119. Windows 10 - bash 명령어 창을 실행했는데 바로 닫히는 경우
11044정성태9/15/201620330VS.NET IDE: 112. Visual Studio 확장 - 편집 화면 내에서 링크를 누르면 외부 웹 브라우저에서 열기
11043정성태9/15/201621744.NET Framework: 606. .NET 스레드 콜 스택 덤프 (7) - ClrMD(Microsoft.Diagnostics.Runtime)를 이용한 방법 [1]파일 다운로드1
11042정성태9/14/201619905오류 유형: 356. Unknown custom metadata item kind: 6
11041정성태9/10/201619394.NET Framework: 605. CLR4 보안 - yield 구문 내에서 SecurityCritical 메서드 사용 불가 - 2번째 이야기
11040정성태9/10/201626688.NET Framework: 604. C# Windows Forms - Drag & Drop 예제 코드 [2]파일 다운로드1
11039정성태9/9/201623207오류 유형: 355. Visual Studio 빌드 오류 - error CS0122: '__ComObject' is inaccessible due to its protection level
11038정성태9/9/201625050VC++: 99. 서로 다른 프로세스에서 WM_DROPFILES 메시지를 전송하는 방법파일 다운로드1
11037정성태9/8/201628283.NET Framework: 603. socket - shutdown 호출이 필요한 사례파일 다운로드1
11036정성태8/29/201624768개발 환경 구성: 297. 소스 코드가 없는 닷넷 어셈블리를 디버깅할 때 지역 변숫값을 확인하는 방법
11035정성태8/29/201620403오류 유형: 354. .NET Reflector - PDB 생성 화면에서 "Clear Store"를 하면 "Index and length must refer to a location within the string" 예외 발생
11034정성태8/25/201624428개발 환경 구성: 296. .NET Core 프로젝트를 NuGet Gallery에 배포하는 방법 [2]
11033정성태8/24/201622280오류 유형: 353. coreclr 빌드 시 error C3249: illegal statement or sub-expression for 'constexpr' function
11032정성태8/23/201621499개발 환경 구성: 295. 최신의 Visual C++ 컴파일러 도구를 사용하는 방법 [1]
11031정성태8/23/201617745오류 유형: 352. Error encountered while pushing to the remote repository: Response status code does not indicate success: 403 (Forbidden).
11030정성태8/23/201620304VS.NET IDE: 111. Team Explorer - 추가한 Git Remote 저장소가 Branch에 보이지 않는 경우
11029정성태8/18/201627430.NET Framework: 602. Process.Start의 cmd.exe에서 stdin만 redirect 하는 방법 [1]파일 다운로드1
11028정성태8/15/201621516오류 유형: 351. Octave 설치 시 JRE 경로 문제
11027정성태8/15/201622572.NET Framework: 601. ElementHost 컨트롤의 메모리 누수 현상
11026정성태8/13/201623565Math: 19. 행렬 연산으로 본 해밍코드
11025정성태8/12/201622267개발 환경 구성: 294. .NET Core 프로젝트에서 "Copy to Output Directory" 처리 [1]
11024정성태8/12/201621563오류 유형: 350. "nProtect GameMon" 실행 중에는 Visual Studio 디버깅이 안됩니다! [1]
... 106  107  108  109  110  111  112  113  114  [115]  116  117  118  119  120  ...