Microsoft MVP성태의 닷넷 이야기
.NET Framework: 506. .NETCore = CoreFX + CoreCLR [링크 복사], [링크+제목 복사],
조회: 19979
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 4개 있습니다.)

.NETCore = CoreFX + CoreCLR

".NET Core"가 공개되었습니다.

CoreCLR Now Open Source 
; http://www.i-programmer.info/news/89-net/8247-coreclr-now-open-source.html

쉽게 말해서 .NET Core는 우리가 알고 있는 ".NET Framework"의 소형 버전이라고 보시면 됩니다.

닷넷으로 만든 프로그램이 동작하려면 크게 2가지 구성요소가 있어야 하는데요. 바로 "JIT" 컴파일 등을 담당하는 런타임 환경이 그 하나이고, 또 다른 구성 요소는 우리가 프로그램을 만들 때 사용하는 여러 타입들이 정의된 "BCL(Base Class Library)"이 그것입니다.

따라서, .NET Core, CoreFX, CoreCLR을 기존의 ".NET Framework"과 비교하면 이렇게 됩니다.

.NET Core      = CoreFX + CoreCLR
.NET Framework = BCL    + CLR

그리고, CoreFX, CoreCLR의 소스 코드가 모두 github에 올라가 진행 중입니다.

dotnet/coreclr 
; https://github.com/dotnet/coreclr

dotnet/corefx 
; https://github.com/dotnet/corefx

게다가 https://github.com/dotnet/coreclr 글의 내용이 흥미진진합니다.

CoreCLR is a subset of the .NET Framework CLR. They share the same codebase and are updated together. For example, an update to the .NET GC improves both CoreCLR and the .NET Framework CLR.


CoreCLR이 .NET Framework CLR과 동일한 코드 기반이기 때문에, 이제는 .NET Framework CLR 측에서 문제가 발생했을 때 추측만이 아니라 검증도 해볼 수 있게 된 것입니다.

마이크로소프트 측은 기존 Mono에서 동작 중인 ASP.NET 5도 CoreCLR이 Linux/Mac용으로 포팅되는 시점에는 CoreCLR로 이전하겠다는 발표도 하고 있습니다.

CoreCLR is now Open Source
; https://devblogs.microsoft.com/dotnet/coreclr-is-now-open-source/

We’ve been talking about ASP.NET 5 for nearly a year now. You can build ASP.NET 5 apps with the .NET Framework or with .NET Core. Today, ASP.NET 5 uses the Mono runtime to run on Linux and Mac. Once .NET Core supports Linux and Mac, then ASP.NET 5 will move to using .NET Core for those platforms.


이렇게 되면 Mono의 향방이 궁금해집니다. 개인적인 의견으로는, Mono가 없어진다기 보다는 CoreCLR의 일정 부분을 흡수하지 않겠는가... 하는 생각을 해봅니다. 혹시 Mono가 CoreCLR 코드 베이스를 완전하게 흡수하는 것은 어떨까요? 글쎄요!!! 그렇다면 하위 호환성을 아예 포기해야 할 것입니다. 가령, Mono Profiler의 규격은 자체 확장한 것이기 때문에 CoreCLR의 Profiler 규격과는 맞지 않습니다. 그런 부분의 호환을 포기한다면 Mono가 CoreCLR을 흡수해 대대적인 성능 향상을 기대해 볼 수도 있을 것입니다. (사실... 저 쪽 동네는 하위 호환을 그다지 중요하지 않게 생각하는 분위기가 있으므로.)




그럼, 어디 ^^ 윈도우 용으로 빌드를 해볼까요?

Developer Guide - Building the repository
; https://github.com/dotnet/coreclr/wiki/Developer-Guide

우선, coreclr-master.zip를 다운로드 받아 압축을 해제합니다. 제 경우에는 e:\coreclr로 했습니다.

그다음 cmake를 다운로드 받습니다.

cmake-3.1.3-win32-x86.zip
; http://www.cmake.org/files/v3.1/cmake-3.1.3-win32-x86.zip

제 경우에는 e:\cmake에 압축을 해제했습니다.

이제 cmd.exe 창을 열고 다음과 같이 SET 명령을 수행해 cmake 폴더를 포함시켜둡니다. (또는 전역 환경 변수에 포함해둡니다.)

SET PATH=%PATH%;e:\cmake\bin

그리고, Visual Studio도 설치되어 있어야 합니다. 없다면 무료 버전인 Visual Studio Community를 다운로드 받아 설치합니다.

Visual Studio Community
; https://app.vssps.visualstudio.com/profile/review?download=true&family=VisualStudio&edition=Community&release=VisualStudio2013Upd4

설치 후, "DIA SDK"가 있는지 아래의 경로에서 확인합니다.

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\DIA SDK"

없으면, 이 글의 마지막에 있는 DIA SDK 관련 설명을 참조하세요.

이걸로 사전 설치 준비 작업은 끝!

(** 2016-08-23 업데이트: 빌드를 위해 Python이 추가되었습니다. 자세한 사항은 Build CoreCLR on Windows 글을 참고하세요.)




자, 이제 명령행에서 루트에 있는 build.cmd 파일을 실행해 빌드해 줍니다.

E:\coreclr>build.cmd
Commencing CoreCLR Repo build

Checking pre-requisites...

Commencing build of native components for Windows_NT.x64.debug

-- The C compiler identification is MSVC 18.0.31101.0
-- The CXX compiler identification is MSVC 18.0.31101.0
-- Check for working C compiler using: Visual Studio 12 2013 Win64
-- Check for working C compiler using: Visual Studio 12 2013 Win64 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 12 2013 Win64
-- Check for working CXX compiler using: Visual Studio 12 2013 Win64 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- The ASM_MASM compiler identification is MSVC
-- Found assembler: c:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/x86_amd64/ml64.exe
-- Configuring done
-- Generating done
-- Build files have been written to: E:/coreclr/binaries/intermediates/Windows_NT.x64.debug
Build started 2015-03-04 10:22:07.

...[생략]...

빌드 하다가 "error CS0518: Predefined type 'System.Object' is not defined or imported" 오류가 발생할 수 있는데 일단 이것은 무시합니다. 그 오류 메시지가 나타날때까지 빌드가 진행되었으면 이미 필요한 DLL들은 다음의 폴더에 생성된 이후입니다. (예를 들어, coreclr.dll, mscorlib.dll, sos.dll, ...)

E:\coreclr\binaries\Product\Windows_NT.x64.debug

이렇게 build.cmd로 빌드를 한번 해주면 "E:\coreclr\binaries\intermediates\Windows_NT.x64.debug\CoreCLR.sln" 파일이 생성됩니다. 이후부터는, 이것을 Visual Studio에 로드해서 컴파일하고 디버깅할 수 있습니다. 물론, "F5 디버깅"도 가능하겠지요? ^^ 방법은 이전에 설명했던 글과 유사하게 진행하시면 됩니다.

OpenCover 소스 코드 분석을 Visual Studio 2013에서 하는 방법
; https://www.sysnet.pe.kr/2/0/2883




그럼, 이제 (Microsoft .NET Framework 런타임이 아닌) "E:\coreclr\binaries\Product\Windows_NT.x64.debug" 폴더에 있는 CoreCLR 런타임으로 간단한 응용 프로그램 하나 실행해 볼까요? ^^

Visual Studio를 이용해 아래와 같은 콘솔 프로젝트를 하나 만들어 빌드하고,

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Main");
            Console.ReadLine();
        }
    }
}

"E:\coreclr\binaries\Product\Windows_NT.x64.debug" 폴더의 corerun.exe를 이용해 다음과 같이 실행해 볼 수 있습니다.

E:\coreclr\binaries\Product\Windows_NT.x64.debug>corerun .\samples\ConsoleApplication1.exe
Main

Console.ReadLine 코드는 일부러 집어 넣은 것입니다. 그 코드로 인해 실행 중에 대기를 하면, 그 시점에 Process Explorer를 이용해 재미있는 결과를 확인할 수 있습니다. 즉, ConsoleApplication1.exe 파일이 CoreRun.exe의 자식이 아닌 CoreRun.exe 자체 내에서 DLL처럼 로드되어 Main 함수가 실행된 것을 확인할 수 있습니다.

corerun_1.png

그러니까, java.exe가 .class파일을 실행하는 것처럼, coreclr에서는 exe파일은 단지 "Main 메서드를 포함하고 있는 dll"이라는 의미에 불과합니다.

물론, 윈도우 환경에서는 ConsoleApplication1.exe 파일을 직접 실행할 수 있고 그런 경우에는 .NET Framework의 영향을 받게 됩니다. (나중에 CoreCLR이 Max/Linux 환경에 포팅이 되면, 방금 전에 만들어 둔 ConsoleApplication1.exe 파일만 다른 환경의 CoreCLR 폴더에 복사해 동일하게 corerun을 이용해 실행해 볼 수 있습니다.)




예전에 아래와 같은 주제로 이야기한 적이 있었지요?

.NET EXE 파일을 닷넷 프레임워크 버전에 상관없이 실행할 수 있을까요? - 두 번째 이야기
; https://www.sysnet.pe.kr/2/0/1746

이젠, corerun.exe 파일과 함께 몇몇 필요한 파일을 함께 배포해 주면 더 이상 .NET Framework 버전에 의존하지 않는 응용 프로그램을 제작할 수 있습니다.

단지, 크로스-플랫폼적인 것이 고려되었기 때문에 아직 WinForm/WPF/WCF와 같은 라이브러리들은 CoreFX에서 지원되지 않아 사용할 수 없습니다. (지원 여부가 불투명 합니다. 아마... 이런 부분은 지원한다고 해도 시간이 제법 걸릴 것입니다.) 현재로써는 ASP.NET 5나 콘솔 응용 프로그램 정도를 개발할 때 쓸 수 있습니다. 아쉽지만! ^^

참고로 맥 운영체제인 OSX에서도 coreclr을 빌드하는 글이 있습니다.

Building and Running .NET’s CoreCLR on OS X
; http://praeclarum.org/post/110552954728/building-and-running-nets-coreclr-on-os-x

점점 더 영역을 확장할 테니 기대해도 좋을 듯 합니다. ^^




지금부터는 빌드 시 겪을 수 있는 오류 상황에 대한 설명입니다.

만약 DIA SDK가 정상적으로 설치되지 않았다면 다음과 같은 오류가 발생합니다.

E:\coreclr>build.cmd Commencing CoreCLR Repo build

Checking pre-requisites...

Commencing build of native components for Windows_NT.x64.debug

Error: DIA SDK is missing at "C:\Program Files (x86)\Microsoft Visual Studio 12.0\DIA SDK". This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "C:\Program Files (x86)\Microsoft Visual Studio 12.0\" but rather at VS install location of previous version. Workaround is to copy DIA SDK fold
er from VS install location of previous version to "C:\Program Files (x86)\Microsoft Visual Studio 12.0\" and then resume build.
Visual Studio 2013 Express does not include the DIA SDK. You need Visual Studio 2013 Community (free).
See: https://github.com/dotnet/coreclr/wiki/Developer-Guide#prerequisites


오류 메시지에 의하면, Visual Studio 2013을 설치할 때 이전 버전의 Visual Studio가 설치되어 있으면 그쪽 폴더에 설치된다고 합니다. 예를 들어, 제 경우에는 컴퓨터에 Visual Studio 2012가 설치되어 있었는데 그래서 다음의 경로에 DIA SDK가 설치되어 있었습니다.

C:\Program Files (x86)\Microsoft Visual Studio 11.0\DIA SDK

따라서 다음의 명령을 관리자 권한으로 실행한 cmd.exe 창에서 실행해 주면 됩니다.

robocopy "C:\Program Files (x86)\Microsoft Visual Studio 11.0\DIA SDK" "C:\Program Files (x86)\Microsoft Visual Studio 12.0\DIA SDK" /S

또 다른 상황으로, 만약 cmake가 정상적으로 PATH에 연결되어 있지 않으면 다음과 같은 오류가 발생합니다.

E:\coreclr>build.cmd Commencing CoreCLR Repo build

Checking pre-requisites...

CMake is a pre-requisite to build this repository but it was not found on the path. Please install CMake from http://www.cmake.org/download/ and ensure it is on your path.


당연히 cmake를 다운로드/압축 풀고 PATH 환경 변수에 경로를 설정해 주면 문제가 해결됩니다.

마지막으로, 본문에서 다뤘던 "CSC : error CS0518: Predefined type 'System.Object' is not defined or imported" 오류가 빌드를 완료하지 못하고 나타나는 문제입니다.

Commencing build of tests for Windows_NT.x64.debug

Doing a clean test build

Starting the Test Build

  Restoring build tools...
  Restoring all package dependencies...
E:\coreclr\tests\src\packages\Microsoft.DotNet.BuildTools.1.0.21-prerelease\lib\packageresolve.targets(25,5): warning : Unable to resolve the assets of System.Diagnostics.Process: Couldn't find a matching group [E:\coreclr\tests\src\Common\Coreclr.TestWrapper\Coreclr.TestWrapper.csproj]
E:\coreclr\tests\src\packages\Microsoft.DotNet.BuildTools.1.0.21-prerelease\lib
...[생략]....

E:\coreclr\tests\src\packages\Microsoft.DotNet.BuildTools.1.0.21-prerelease\lib\packageresolve.targets(25,5): warning : Unable to resolve the assets of System.Reflection.Primitives: Couldn't find a matching group [E:\coreclr\tests\src\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj]
CSC : error CS0518: Predefined type 'System.Object' is not defined or imported
[E:\coreclr\tests\src\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj]

...[생략]....

최초 발생하는 오류는 System.Object를 찾을 수 없다는 것입니다.

CSC : error CS0518: Predefined type 'System.Object' is not defined or imported [E:\coreclr\tests\src\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj]

왜냐하면 해당 csproj 프로젝트 빌드가 nostdlib 옵션으로 컴파일되기 때문인데 구체적인 해결 방법은 다음에 더 알아보도록 하겠습니다. 지금은 일단, 이 빌드 오류가 발생해도 CoreCLR 빌드는 정상적으로 되었으므로 무시해도 좋습니다.




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 4/23/2023]

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

비밀번호

댓글 작성자
 



2015-03-13 04시05분
[ryujh] 안녕하세요.

본문 중에

.NET Core = CoreFX + CoreCLR
.NET Framework = BCL + CLR

이런 관계인데 .NET Framework Client Profile 과 위의 것의 관계는 어떤지 문의합니다.

본문 아래의 실행법은 java의 영향을 받은 것인가요?


저는 아직도 vs2008을 사용하고 있는데(가끔 vs2012 사용) 이제 버전업을 해야할 것 같습니다.

감사합니다.
[guest]
2015-03-13 04시28분
.NET Framework Client Profile은 위의 관계에 낄 수는 없습니다. ^^ .NET 런타임이 40MB 넘게 무거워지니까, 서버 쪽 구성요소같은 클라이언트 응용 프로그램 제작에 잘 쓰이지 않는 구성 요소를 제거해서 만든 .NET 런타임이 "Client Profile"입니다. (ClickOnce 응용 프로그램 배포를 빠르게 하기 위해 만들어진 듯 하지만... 실상은 얼마 차이기 나지 않기 때문에 혹시 모를 타입 사용을 위해 Full Framework 버전을 보통 사용하게 됩니다.)

java의 영향을 받았다기 보다는, 운영체제에 의해 직접 해석되는 실행 모듈이 아니기 때문에 저렇게 다른 프로세스에 실려서 실행할 수 밖에 없습니다.
정성태
2016-08-23 02시43분
copy bin\Product\Windows_NT.x64.debug\clrjit.dll ..\coreclr-demo\runtime
copy bin\Product\Windows_NT.x64.debug\CoreRun.exe ..\coreclr-demo\runtime
copy bin\Product\Windows_NT.x64.debug\coreclr.dll ..\coreclr-demo\runtime
copy bin\Product\Windows_NT.x64.debug\mscorlib.dll ..\coreclr-demo\runtime
copy bin\Product\Windows_NT.x64.debug\System.Private.CoreLib.dll ..\coreclr-demo\runtime
정성태
2016-08-23 02시49분
copy bin\Windows_NT.AnyCPU.Debug\System.Console\System.Console.dll ..\coreclr-demo\runtime
copy bin\Windows_NT.AnyCPU.Debug\System.Diagnostics.Debug\System.Diagnostics.Debug.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.IO\System.IO.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.IO.FileSystem.Primitives\System.IO.FileSystem.Primitives.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.Runtime\System.Runtime.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.Runtime.InteropServices\System.Runtime.InteropServices.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.Text.Encoding\System.Text.Encoding.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.Text.Encoding.Extensions\System.Text.Encoding.Extensions.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.Threading\System.Threading.dll ..\coreclr-demo\runtime
copy bin\AnyOS.AnyCPU.Debug\System.Threading.Tasks\System.Threading.Tasks.dll ..\coreclr-demo\runtime
정성태
2017-01-31 01시00분
정성태

1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13489정성태12/19/20232178개발 환경 구성: 697. GoLand에서 ldflags 지정 방법
13488정성태12/18/20232112오류 유형: 884. HTTP 500.0 - 명령행에서 실행한 ASP.NET Core 응용 프로그램을 실행하는 방법
13487정성태12/16/20232416개발 환경 구성: 696. C# - 리눅스용 AOT 빌드를 docker에서 수행 [1]
13486정성태12/15/20232230개발 환경 구성: 695. Nuget config 파일에 값 설정/삭제 방법
13485정성태12/15/20232121오류 유형: 883. dotnet build/restore - error : Root element is missing
13484정성태12/14/20232201개발 환경 구성: 694. Windows 디렉터리 경로를 WSL의 /mnt 포맷으로 구하는 방법
13483정성태12/14/20232335닷넷: 2184. C# - 하나의 resource 파일을 여러 프로그램에서 (AOT 시에도) 사용하는 방법파일 다운로드1
13482정성태12/13/20233005닷넷: 2183. C# - eFriend Expert OCX 예제를 .NET Core/5+ Console App에서 사용하는 방법 [2]파일 다운로드1
13481정성태12/13/20232312개발 환경 구성: 693. msbuild - .NET Core/5+ 프로젝트에서 resgen을 이용한 리소스 파일 생성 방법파일 다운로드1
13480정성태12/12/20232706개발 환경 구성: 692. Windows WSL 2 + Chrome 웹 브라우저 설치
13479정성태12/11/20232373개발 환경 구성: 691. WSL 2 (Ubuntu) + nginx 환경 설정
13477정성태12/8/20232624닷넷: 2182. C# - .NET 7부터 추가된 Int128, UInt128 [1]파일 다운로드1
13476정성태12/8/20232314닷넷: 2181. C# - .NET 8 JsonStringEnumConverter의 AOT를 위한 개선파일 다운로드1
13475정성태12/7/20232411닷넷: 2180. .NET 8 - 함수 포인터에 대한 Reflection 정보 조회파일 다운로드1
13474정성태12/6/20232228개발 환경 구성: 690. 닷넷 코어/5+ 버전의 ilasm/ildasm 실행 파일 구하는 방법 - 두 번째 이야기
13473정성태12/5/20232501닷넷: 2179. C# - 값 형식(Blittable)을 메모리 복사를 이용해 바이트 배열로 직렬화/역직렬화파일 다운로드1
13472정성태12/4/20232250C/C++: 164. Visual C++ - InterlockedCompareExchange128 사용 방법
13471정성태12/4/20232349Copilot - To enable GitHub Copilot, authorize this extension using GitHub's device flow
13470정성태12/2/20232682닷넷: 2178. C# - .NET 8부터 COM Interop에 대한 자동 소스 코드 생성 도입파일 다운로드1
13469정성태12/1/20232444닷넷: 2177. C# - (Interop DLL 없이) CoClass를 이용한 COM 개체 생성 방법파일 다운로드1
13468정성태12/1/20232336닷넷: 2176. C# - .NET Core/5+부터 달라진 RCW(Runtime Callable Wrapper) 대응 방식파일 다운로드1
13467정성태11/30/20232439오류 유형: 882. C# - Unhandled exception. System.Runtime.InteropServices.COMException (0x800080A5)파일 다운로드1
13466정성태11/29/20232609닷넷: 2175. C# - DllImport 메서드의 AOT 지원을 위한 LibraryImport 옵션
13465정성태11/28/20232349개발 환경 구성: 689. MSBuild - CopyToOutputDirectory가 "dotnet publish" 시에는 적용되지 않는 문제파일 다운로드1
13464정성태11/28/20232491닷넷: 2174. C# - .NET 7부터 UnmanagedCallersOnly 함수 export 기능을 AOT 빌드에 통합파일 다운로드1
13463정성태11/27/20232401오류 유형: 881. Visual Studio - NU1605: Warning As Error: Detected package downgrade
1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...