.Net开源之corefx、coreclr初探(三)

本文介绍利用编译出来的coreclr来执行C#编写的Hello coreclr程序。我的机器环境是Win 7 x64 En,VS2013.

(1)编译test程序,根据开发guide,执行build指令如下:

<repo_root>\tests\buildtest.cmd x64 release clean在我的环境中,编译成功了,没有出错误,开发guide中说明了如果出错误的解决办法。

同样编译完成后,会生成一个VS工程文件。为何要编译test,原因是我这边的Win7下,如果直接运行HelloCoreclr.exe程序的话,,会提示找不到dll,而这些dll利用test编译后,

能够得到。

(2)设置环境变量CORE_ROOT

CORE_ROOT的路径指向<..\coreclr\binaries\Product\x64\debug>下

(3)编译helloworld程序

自己用C#写一个hello world程序,编译后生成exe文件,并将该文件拷贝粘贴到此路径下

(4)可以直接用命令好启动corerun.exe,运行helloworld程序。如下图为我创建的简单的hello coreclr!程序,由corerun.exe启动后的执行结果。此时已经脱离的默认的.net运行库,而是用开源的coreclr运行库运行哦。

(5)api-ms-win-core-winrt-string-l1-1-0.dll找不到问题

实际上在第四步执行时,并不顺利,在win7下会出现dll找不到的错误,错误框如下。解决办法是将第一步中test编译出来的文件夹<..\coreclr\tests\src\packages\Microsoft.DotNet.CoreCLR.TestDependencies.1.0.0-prerelease\lib\aspnetcore50>

(6)coreclr的debug

开发guide提供了如何对coreclr进行debug的方法,原文如下,主要需要做的就是将coreclr.sln工程中的INSTALL项目属性进行设置。根据说明,设置情况如图:

Debugging CoreCLR

Set Command=$(SolutionDir)..\product\$(Platform)\$(Configuration)\corerun.exeThis points to the folder where the built runtime binaries are present.Set Command Arguments=<managed app you wish to run>(e.g. HelloWorld.exe)Set Working Directory=$(SolutionDir)..\product\$(Platform)\$(Configuration)This points to the folder containing CoreCLR binaries.Press F11 to start debugging at wmain in corerun (or set a breakpoint in source and press F5 to run to it)As an example, set a breakpoint for the EEStartup function in ceemain.cpp to break into CoreCLR startup.

Steps 1-8 only need to be done once, and then (9) can be repeated whenever you want to start debugging. The above can be done with Visual Studio 2013.

按F11执行后,进入程序入口如下,然后就可以单步调试了,(PS:我这边环境变量没有设置也是单步调试的时候发现的,因为单步调试启动自己的Hello World程序时,会提示coreclr.dll加载失败,原因就是没有设置环境变量。)

综上,windows下以开源coreclr运行hello world程序就实现了。想了解coreclr底层的东西,单步跟着代码走就行了。

教育人的,激励人的,安慰人不开心的. 或者是 诗词 诗经里的..

.Net开源之corefx、coreclr初探(三)

相关文章:

你感兴趣的文章:

标签云: