기본 콘텐츠로 건너뛰기

[ MSBUILD] 개념 잡기 - #2 환경에 따라서 빌드 구성하기.

기본적인 설정과 동작에 관련된 부분은 이전 게시글에서 알아 보았다. 이번에는 좀 더 다양한 정보를 기준으로 활용할 수 있는 빌드 스크립트를 구성하고 실행해 보도록 한다.

New basic build script

  파일의 이름은 “msbuild-basic-template.xml” 하고 아래의 내용과 같이 새로운 구성의 빌드 스크립트를 구성하도록 하자.




    
    
        %3b
        &
        <
        >
        "
        $(StraightQuotationMark)
        '
    

    
    
        $(MSBuildProjectDirectory)
    

    
    
        devenv.exe
    

    
    
        x64
        Win32
        Debug
        $(Configuration)|$(Platform)
    

    
    

    
    

    
        TestProject.sln">
            $(Configuration)
            $(Platform)
            %(Configuration)|%(Platform)
        
    

    
        
        
    

    
        
        

        
    

    
        
    

위의 코드를 기준으로 필요한 기능들을 상황에 따라서 추가해서 작업을 하면 된다.

Folders

  만일 특정한 솔루션을 빌드하여야 하는데 특정 폴더들에 대해서 작업을 하여야 하는 상황이라면 아래와 같이 폴더 부분을 조정해 주면 된다.



    $(MSBuildProjectDirectory)
    
    $(RootDir)\..\Shared

당연한 말이지만 특정 폴더와 같이 자동화라는 것이 무색하게 지정을 해서는 안 된다.

Conditional Configuration

  이제 빌드를 위한 설정과 플랫폼등에 대한 정보를 설정하면 된다.



    x64
    Win32
    Debug
    $(Configuration)|$(Platform)

Platform 은 x64, x86 (또는 Win32) 의 빌드인지를 의미하는 것이다. 위의 설정은 $(Platform) 이 사전에 정의된 값이 없는 경우에 조건을 지정해서 값을 지정하는 설정이다.

Solution Setting


    
        $(Configuration)
 $(Platform)
 %(Configuration)|%(Platform)
    

TestProject.sln 이라는 솔루션 파일을 설정하고 상위에서 정의된 $(Configuration), $(Platform) 값에 따라서 빌드를 하게 된다. 이런 조합이 나올 수 있는 경우는 다음과 같다.

  • Debug|Win32
  • Release|Win32
  • Debug|x64
  • Release|x64
Solution Build


    
    
<Exec Command="$(DevEnv) $(Quot)%(ProjectReferences.FullPath)$(Quot) /Build $(Quot)%(ProjectReferences.BuildCondition)$(Quot)"
      ContinueOnError="false"
      IgnoreExitCode="false"
/>

  에서 설정된 것과 같이 $(DevEnv) 를 호출해서 실행하게 된다. 구성된 Command 가 복잡해 보이지만 결국 풀어서 쓰면 아래와 같은 실행 명령인 것이다.

"devenv.exe "C:\Temp\TestProjects.sln" /Build "Debug|Win32"

위에 정의된 $(DevEnv), $(Quot), %(ProjectReferences.FullPath), %(ProjectReferences.BuildCondition) 등의 변수를 치환하면 좀 더 이해하기 쉽게 생각할 수 있다.

Execute with Configuration, Platform

  다음과 같이 Platform 의 경우는 값을 설정해 줄 수가 있다.

[ Win32 빌드 배치 파일 ]
@echo off
SETLOCAL
call "%VS90COMNTOOLS%\..\..\VC\vcvarsall.bat" x86
"%WINDIR%\Microsoft.NET\Framework\v3.5\msbuild.exe" %*
SET ERR_LEVEL=%errorlevel%
ENDLOCAL
exit /b %ERR_LEVEL%

[ x64 빌드 배치 파일 ]
@echo off
SETLOCAL
call "%VS90COMNTOOLS%\..\..\VC\vcvarsall.bat" x64
"%WINDIR%\Microsoft.NET\Framework64\v3.5\msbuild.exe" %*
SET ERR_LEVEL=%errorlevel%
ENDLOCAL
exit /b %ERR_LEVEL%

위의 빌드 배치 파일과 같이 붉은 색으로 표시된 정보를 설정하므로써 Platform 정보와 관련된 MSBuild 실행 파일을 구분해서 처리하면 된다.

  그리고 Debug 또는 Release 에 대한 Confiugration 정보는 빌드 배치 파일에 인자로 설정하면 전달하여 처리가 가능하다.

msbuild_vs2013_x86 build.xml /p:Configuration=Debug
  이상으로 환경에 따라서 빌드를 구성하는 방법에 대해서 기존 게시물에 추가해서 알아 보았다. 기존 설정과 별로 달라진 것은 없지만 이렇게 하나씩 필요한 상황들을 추가하면서 처리를 하면 된다.

MSBuild 예약 속성들

  Visual Studio 2013 을 설치해서 사용하는 환경을 기준으로 아래에 정리한 내용과 같이 이미 MSBuild에서 예약으로 설정되어 있는 값들이 존재한다.

Property
Description
Reserved or Well-Known
MSBuildBinPath
MSBuild 실행 파일이 존재하는 경로를 의미한다.
(Ex, C:\Windows\Microsoft.Net\Framework\versionNumber).
맨 뒤의 "\"는 포함되면 안 된다.
예약
MSBuildExtensionsPath
Introduced in the .NET Framework 4: there is no difference between the default values of MSBuildExtensionsPath andMSBuildExtensionsPath32. You can set the environment variableMSBUILDLEGACYEXTENSIONSPATH to a non-null value to enable the behavior of the default value of MSBuildExtensionsPath in earlier versions.
In the .NET Framework 3.5 and earlier, the default value ofMSBuildExtensionsPath points to the path of the MSBuild subfolder under the \Program Files\ or \Program Files (x86) folder, depending on the bitness of the current process. For example, for a 32-bit process on a 64-bit machine, this property points to the \Program Files (x86) folder. For a 64-bit process on a 64-bit machine, this property points to the \Program Files folder.
Do not include the final backslash on this property.
This location is a useful place to put custom target files. For example, your target files could be installed at \Program Files\MSBuild\MyFiles\Northwind.targets and then imported in project files by using this XML code:
Well-Known
MSBuildExtensionsPath32
The path of the MSBuild subfolder under the \Program Files or \Program Files (x86) folder. This path always points to the 32-bit \Program Files folder on a 32-bit machine and \Program Files (x86) on a 64-bit machine. See also MSBuildExtensionsPath and MSBuildExtensionsPath64.
Do not include the final backslash on this property.
Well-Known
MSBuildExtensionsPath64
The path of the MSBuild subfolder under the \Program Files folder. For a 64-bit machine, this path always points to the \Program Files folder. For a 32-bit machine, this path is blank. See also MSBuildExtensionsPath andMSBuildExtensionsPath32.
Do not include the final backslash on this property.
Well-Known
MSBuildLastTaskResult
true if the previous task completed without any errors (even if there were warnings), or false if the previous task had errors. Typically, when an error occurs in a task, the error is the last thing that happens in that project. Therefore, the value of this property is never false, except in these scenarios:
Reserved
MSBuildNodeCount
The maximum number of concurrent processes that are used when building. This is the value that you specified for /maxcpucount on the command line. If you specified /maxcpucount without specifying a value, then MSBuildNodeCount specifies the number of processors in the computer. For more information, see MSBuild Command-Line Referenceand Building Multiple Projects in Parallel with MSBuild.
Reserved
MSBuildProgramFiles32
The location of the 32-bit program folder; for example, C:\Program Files (x86).
Do not include the final backslash on this property.
Reserved
MSBuildProjectDefaultTargets
The complete list of targets that are specified in the DefaultTargetsattribute of the Project element. For example, the following Projectelement would have an MSBuildDefaultTargets property value of A;B;C:
Reserved
MSBuildProjectDirectory
MSBuild 가 솔루션이나 프로젝트를 빌드할 때 사용할 폴더를 의미하는 것으로 보통은 빌드 스크립트가 존재하는 경로라고 이해하면 된다.
(Ex. C:\MyCompany\MyProduct)
마지막에 "\"는 포함되면 안 된다.
예약
MSBuildProjectDirectoryNoRoot
The value of the MSBuildProjectDirectory property, excluding the root drive.
Do not include the final backslash on this property.
Reserved
MSBuildProjectExtension
The file name extension of the project file, including the period; for example, .proj.
Reserved
MSBuildProjectFile
The complete file name of the project file, including the file name extension; for example, MyApp.proj.
Reserved
MSBuildProjectFullPath
The absolute path and complete file name of the project file, including the file name extension; for example, C:\MyCompany\MyProduct\MyApp.proj.
Reserved
MSBuildProjectName
The file name of the project file without the file name extension; for example, MyApp.
Reserved
MSBuildStartupDirectory
The absolute path of the folder where MSBuild is called. By using this property, you can build everything below a specific point in a project tree without creating dirs.proj files in every directory. Instead, you have just one project—for example, c:\traversal.proj, as shown here:

    
        
    
    
        
    

To build at any point in the tree, type:
msbuild c:\traversal.proj
Do not include the final backslash on this property.
Reserved
MSBuildThisFile
The file name and file extension portion of MSBuildThisFileFullPath.
Reserved
MSBuildThisFileDirectory
The directory portion of MSBuildThisFileFullPath.
Include the final backslash in the path.
Reserved
MSBuildThisFileDirectoryNoRoot
The directory portion of MSBuildThisFileFullPath, excluding the root drive.
Include the final backslash in the path.
Reserved
MSBuildThisFileExtension
The file name extension portion of MSBuildThisFileFullPath.
Reserved
MSBuildThisFileFullPath
The absolute path of the project or targets file that contains the target that is running.
Tip Tip
You can specify a relative path in a targets file that's relative to the targets file and not relative to the original project file.
Reserved
MSBuildThisFileName
The file name portion of MSBuildThisFileFullPath, without the file name extension.
Reserved
MSBuildToolsPath
The installation path of the MSBuild version that's associated with the value of MSBuildToolsVersion.
Do not include the final backslash in the path.
This property cannot be overridden.
Reserved
MSBuildToolsVersion
The version of the MSBuild Toolset that is used to build the project.
Note Note
An MSBuild Toolset consists of tasks, targets, and tools that are used to build an application. The tools include compilers such as csc.exe and vbc.exe. For more information, see MSBuild Toolset (ToolsVersion), and Standard and Custom Toolset Configurations.
Reserved

댓글

이 블로그의 인기 게시물

OData 에 대해서 알아보자.

얼마 전에 어떤 회사에 인터뷰를 하러 간 적이 있었다. 당시 그 회사는 자체 솔루션을 개발할 기술인력을 찾고 있었고 내부적으로 OData를 사용한다고 했다. 좀 창피한 이야기일 수도 있지만 나름 기술적인 부분에서는 많은 정보를 가지고 있다고 했던 것이 무색하게 OData란 단어를 그 회사 사장님에게서 처음 들었다. 작고, 단순한 사이트들만을 계속해서 작업을 하다 보니 어느덧 큰 줄기들을 잃어버린 것을 느끼기 시작했다. 명색이 개발이 좋고, 기술적인 기반을 만들려고 하는 인간이 단어조차도 모른다는 것은 있을 수 없는 것이라서 다시 새로운 단어들과 개념들을 알아보는 시간을 가지려고 한다. OData (Open Data Protocol) 란? 간단히 정리하면 웹 상에서 손쉽게 데이터를 조회하거나 수정할 수 있도록 주고 받는 웹(프로토콜)을 말한다. 서비스 제공자 입장에서는 웹으로 데이터를 제공하는 방식으로 각 포탈 사이트들이 제공하는 OPEN API 포맷을 독자적인 형식이 아니라 오픈된 공통규약으로 제공 가능하며, 개발자는 이 정보를 다양한 언어의 클라이언트 라이브러리로 어플리케이션에서 소비할 수 있도록 사용하면 된다. 공식 사이트는 www.odata.org 이며 많은 언어들을 지원하고 있다. 좀더 상세하게 정의를 해 보면 OData는 Atom Publishing Protocol  (RFC4287) 의 확장 형식이고 REST (REpresentational State Transfer) Protocol 이다. 따라서 웹 브라우저에서 OData 서비스로 노출된 데이터를 볼 수 있다. 그리고 AtomPub 의 확장이라고 했듯이 데이터의 조회만으로 한정되는 것이 아니라 CRUD 작업이 모두 가능하다. Example 웹 브라우저에서 http://services.odata.org/website/odata.svc 를 열어 보도록 하자. This XML file does not appear to have any style in...

C# 에서 Timer 사용할 때 주의할 점.

예전에 알고 지내시던 분의 질문을 받았다. Windows Forms 개발을 하는데, 주기적 (대략 1분)으로 데이터 요청을 하는 프로그램을 작성하기 위해서 Timer 를 사용하는데, 어떤 기능을 처리해야 하기 때문에 Sleep 을 같이 사용했다고 한다. 여기서 발생하는 문제는 Sleep 5초를 주었더니, Timer 까지 5초 동안 멈춘다는 것이다. Timer 라는 것은 기본적으로 시간의 흐름을 측정하는 기능이기 때문에 Sleep 을 했다고 해서 Timer 가 멈추는 일은 생겨서는 안된다. 그러나 실제 샘플을 만들어 보면 ... Timer 가 Sleep 만큼 동작이 멈추는 것을 확인할 수 있다. Windows Forms 는 UI Thread 를 사용하는 것으로 최적화 되어 있으며 여기서 Timer 를 쓰면 UI Thread 에 최적화된 System.Windows.Forms.Timer 가 사용된다. 여기서 문제의 발생이 시작되는 것이다. Sleep 을 사용하게 되면 UI Thread 가 Sleep 이 걸리기 때문에 여기에 속한 Timer 까지도 멈추는 것이다. 이런 문제를 해결하기 위해서는 System.Threading.Timer 를 사용해야 한다. 이 Timer 는 별도의 Thread 에서 동작하기 때문에 Sleep 의 영향을 받지 않는다. 언뜻 보면 쉬운 해결 방법인 것 같지만 Thread 가 분리되었기 때문에 Timer 가 돌아가는 Thread 에서 UI Thread 의 메서드나 컨트롤에 접근하기 위해서는 별도의 명령을 사용해야 하는 문제가 존재한다. 자~ 그럼 여기서 Timer 에 대해서 다시 한번 정리해 보도록 하자. .NET 에서 제공하는 Timer 들 .NET 에서는 기본적으로 3가지 Timer를 제공하고 있다. (MSDN) System.Windows.Forms.Timer - 사용자가 지정한 간격마다 이벤트를 발생시키며 Windows Forms 응용 프로그램에서 사용할 수 있도록 최적화 되어 있다. System...

[Logging] NLog 사용법 정리...

SCSF 에는 기본적으로 Enterprise Library가 사용된다. 예전에도 그랬지만 기능은 훌륭하고 많은 부분에서 최적화(?)된 것일지도 모르지만, 역시나 사용하기에는 뭔가 모르게 무겁고, 사용하지 않는 기능이 더 많다라는 느낌을 지울수가 없다. 이번 프로젝트도 SCSF를 기반으로 하고 있지만, Enterprise Library를 걷어내고 각 부분에 전문화된 오픈 소스를 사용하기로 하였다. 예전에는 Log4Net을 사용했지만, 대량 사용자 환경에서는 메모리 누수와 기타 문제점이 존재한다는 MS 컨설턴트(?)의 전해진 말을 들은 후로는 사용하지 않는다. 대안으로 사용하는 것이 NLog 이다. 조금 후에는 3.0 버전도 나온다고 홈 페이지에 기재되어 있지만, 그 때가 되면 프로젝트는 끝나기 때문에 현재 2.1.0 버전을 사용하기로 했다. [원본 출처] http://cloverink.net/most-useful-nlog-configurations-closed/ 위의 참조 자료에는 다양한 정보들이 존재하므로 꼭 링크를 통해서 관련된 정보를 확인하고 이해하는 것이 좋을 듯 하다. 여기서는 당장 필요한 부분만을 정리하도록 한다. [ Logger 찾기 ] 기본적으로 Logger가 존재하는 클래스를 기반으로 Logger 정보를 구성한다. Logger logger = LogManager.GetCurrentClassLogger(); 주로 Namespace 기반으로 Logger를 설정하는 경우에 유연하게 사용할 수 있다. 또 다른 방법으로는 지정한 문자열로 특정 Logger를 직접 선택하는 방법도 제공된다. 이를 혼용해서 Namespace와 직접 지정 방식을 같이 사용할 수도 있다. 물론 Logger 환경 설정에서 Wildcard (*)를 지정할 수도 있다. Logger logger = LogManager.GetLogger("Database.Connect"); Logger logger = LogManager.Get...