好奇环境是怎样的,先不看任何东西,自己翻翻看。
- 不想折腾环境,运行一个docker容器就一把搞定了。
docker run -it microsoft/dotnet:latest
- 新建一个工程,流行的风格,嗯,挺上路的吗。
mkdir hwappcd hwappdotnet new
看看目录结构
-rwxr--r-- 1 root root 202 Jun 22 03:31 Program.cs*-rwxr--r-- 1 root root 348 Jun 22 03:31 project.json*
挑个小刺:每个文件居然全设定成了可执行属性,看着就怪啊。 Program.cs
就一个Hellow World没啥看头。 project.json
:
{ "version": "1.0.0-*", "buildOptions": { "debugType": "portable", "emitEntryPoint": true }, "dependencies": {}, "frameworks": { "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0" } }, "imports": "dnxcore50" } }}
也还好。 dnxcore50的名称以后可能会换掉。哎,.NET本身的名称都不好,上梁不正下梁歪。
小刺:最好直接换成yaml,都有点烦了JSON了,那双引号,什么破设计,另外也不能写注释。所以人家SpringBoot默认都换成yaml了。
- 开始安装依存lib然后执行了
dotnet restore #####这个命令吓人,求你改掉吧。实际是相当于npm install的意思,安装依赖lib#####dotnet run
自然是得到了Hello World。
编译生成的目录和Windows下的习惯一样,bin/Debug,和obj
bin/Debug/netcoreapp1.0/hwapp.dllbin/Debug/netcoreapp1.0/hwapp.deps.jsonbin/Debug/netcoreapp1.0/hwapp.pdbbin/Debug/netcoreapp1.0/hwapp.runtimeconfig.dev.jsonbin/Debug/netcoreapp1.0/hwapp.runtimeconfig.json
- 看看这个
dotnet
是何方神圣
root@88dab4dc4160:/hwapp# ls -lF `which dotnet`lrwxrwxrwx 1 root root 24 Jun 30 21:00 /usr/bin/dotnet -> /usr/share/dotnet/dotnet*
干脆把/usr/share/dotnet/
下的东西都翻出来看看
./dotnet./host/fxr/1.0.1/libhostfxr.so./sdk/1.0.0-preview2-003121/corehost #这个显然是主角luancher了./sdk/1.0.0-preview2-003121/libhostfxr.so./sdk/1.0.0-preview2-003121/libhostpolicy.so./shared/Microsoft.NETCore.App/1.0.0/corehost./shared/Microsoft.NETCore.App/1.0.0/dotnet./shared/Microsoft.NETCore.App/1.0.0/libclrjit.so #JIT Compiler./shared/Microsoft.NETCore.App/1.0.0/libcoreclr.so #CLR运行时./shared/Microsoft.NETCore.App/1.0.0/libcoreclrtraceptprovider.so./shared/Microsoft.NETCore.App/1.0.0/libdbgshim.so ./shared/Microsoft.NETCore.App/1.0.0/libhostfxr.so./shared/Microsoft.NETCore.App/1.0.0/libhostpolicy.so./shared/Microsoft.NETCore.App/1.0.0/libmscordaccore.so./shared/Microsoft.NETCore.App/1.0.0/libmscordbi.so./shared/Microsoft.NETCore.App/1.0.0/libsos.so./shared/Microsoft.NETCore.App/1.0.0/libsosplugin.so./shared/Microsoft.NETCore.App/1.0.0/libuv.so ##居然你也在。异步编程用的。Node.JS里用它做event loop的。./shared/Microsoft.NETCore.App/1.0.0/System.Globalization.Native.so./shared/Microsoft.NETCore.App/1.0.0/System.IO.Compression.Native.so./shared/Microsoft.NETCore.App/1.0.0/System.Native.so./shared/Microsoft.NETCore.App/1.0.0/System.Net.Http.Native.so./shared/Microsoft.NETCore.App/1.0.0/System.Net.Security.Native.so./shared/Microsoft.NETCore.App/1.0.0/System.Security.Cryptography.Native.so
这应该就是最核心的干货了。
还有其他好多dll的,和xarmarine里的那一套比较像
./sdk/1.0.0-preview2-003121/.version./sdk/1.0.0-preview2-003121/csc.deps.json./sdk/1.0.0-preview2-003121/csc.dll./sdk/1.0.0-preview2-003121/csc.runtimeconfig.json./sdk/1.0.0-preview2-003121/dotnet.deps.json./sdk/1.0.0-preview2-003121/dotnet.dll./sdk/1.0.0-preview2-003121/dotnet.runtimeconfig.json./sdk/1.0.0-preview2-003121/Microsoft.ApplicationInsights.dll./sdk/1.0.0-preview2-003121/Microsoft.DiaSymReader.dll./sdk/1.0.0-preview2-003121/Microsoft.DotNet.Archive.dll..../sdk/1.0.0-preview2-003121/Microsoft.DotNet.Configurer.dll..../sdk/1.0.0-preview2-003121/Microsoft.Extensions.Testing.Abstractions.dll./sdk/1.0.0-preview2-003121/Newtonsoft.Json.dll./sdk/1.0.0-preview2-003121/NuGet.Client.dll./sdk/1.0.0-preview2-003121/NuGet.CommandLine.XPlat.dll..../sdk/1.0.0-preview2-003121/NuGet.RuntimeModel.dll./sdk/1.0.0-preview2-003121/NuGet.Versioning.dll./sdk/1.0.0-preview2-003121/nuGetPackagesArchive.lzma./sdk/1.0.0-preview2-003121/runtimes/unix/lib/netstandard1.3/System.Diagnostics.TraceSource.dll./sdk/1.0.0-preview2-003121/runtimes/win-x64/native/Microsoft.DiaSymReader.Native.amd64.dll..../sdk/1.0.0-preview2-003121/runtimes/win8-arm/native/Microsoft.DiaSymReader.Native.arm.dll./sdk/1.0.0-preview2-003121/System.Diagnostics.TextWriterTraceListener.dll..../sdk/1.0.0-preview2-003121/System.Xml.XmlSerializer.dll./shared/Microsoft.NETCore.App/1.0.0/Microsoft.CodeAnalysis.CSharp.dll..../shared/Microsoft.NETCore.App/1.0.0/Microsoft.VisualBasic.dll #VB.NET难道也要支持,扔了算了。..../shared/Microsoft.NETCore.App/1.0.0/Microsoft.Win32.Registry.dll #Registry??./shared/Microsoft.NETCore.App/1.0.0/mscorlib.dll./shared/Microsoft.NETCore.App/1.0.0/mscorlib.ni.dll./shared/Microsoft.NETCore.App/1.0.0/sosdocsunix.txt./shared/Microsoft.NETCore.App/1.0.0/System.AppContext.dll..../shared/Microsoft.NETCore.App/1.0.0/System.IO.dll #亲切..../shared/Microsoft.NETCore.App/1.0.0/System.Native.a #这是给谁用啊./shared/Microsoft.NETCore.App/1.0.0/System.Net.Http.dll..../shared/Microsoft.NETCore.App/1.0.0/System.Reflection.dll..../shared/Microsoft.NETCore.App/1.0.0/System.Runtime.dll..../shared/Microsoft.NETCore.App/1.0.0/System.Runtime.InteropServices.dll #这是什么节奏, Native调用吗?..../shared/Microsoft.NETCore.App/1.0.0/System.Runtime.Loader.dll..../shared/Microsoft.NETCore.App/1.0.0/System.Security.Cryptography.Csp.dll..../shared/Microsoft.NETCore.App/1.0.0/System.Security.Cryptography.OpenSsl.dll..../shared/Microsoft.NETCore.App/1.0.0/System.Text.RegularExpressions.dll..../shared/Microsoft.NETCore.App/1.0.0/System.Xml.ReaderWriter.dll./shared/Microsoft.NETCore.App/1.0.0/System.Xml.XDocument.dll...
另外,机器里面还有一些.nuget管理包用的目录,整体很干净。
继续吐槽,NuGet这样的名称还不趁机改掉啊,难受死了。
回头再接着分析。
- 看看corehost,和如何debug。 看了corehost的命令行,回到hwap目录下试着用一下
root@88dab4dc4160:/hwapp# /usr/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/corehost ./bin/Debug/netcoreapp1.0/hwapp.dllHello World!
看来就是他了,好了,入口找到了。
再看看详细信息,下次再分析一下。
root@88dab4dc4160:/hwapp# COREHOST_TRACE=1 /usr/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/corehost ./bin/Debug/netcoreapp1.0/hwapp.dll 2>&1 |less一堆结果爆屏,不贴了,能够看到用到什么文件。...
dotnet和corehost的命令行帮助太少,看不出如何debug,但肯定能够调试,只是这些细节看来还没做完备啊。
下次在看看如何debug。然后在学学ASP.NET Core。