OwinHost.exe: While some will want to write a custom process to run Katana Web applications, many would prefer to simply launch a pre-built executable that can start a server and run their application. For this scenario, the Katana component suite includes OwinHost.exe. When run from within a project’s root directory, this executable will start a server (it uses the HttpListener server by default) and use conventions to find and run the user’s startup class. For more granular control, the executable provides a number of additional command line parameters.html
K Commands: Whenever you want to run your app in command line using K* commands, you will use k run. The K command is your entry point to the runtime. To run an application you can use K run to build you can use K build, and all other commands that are about taking your application and running it.git
K Commands 是 APS.NET 5 引出的,根聽說明知道它是加載與啓動 OWIN 組件的一個命令,那 OwinHost.exe 是什麼?它實際上是以前 OWIN 的實現 Katana 項目中的一個東西,這個東西是什麼?看一下源碼結構:github
摘自 Program.cs 中的一段源代碼:app
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using Microsoft.Owin.Hosting; using Microsoft.Owin.Hosting.Services; using Microsoft.Owin.Hosting.Starter; using Microsoft.Owin.Hosting.Utilities; using OwinHost.Options; namespace OwinHost { public static class Program { public static void RunServer(StartOptions options) { if (options == null) { return; } string boot; if (!options.Settings.TryGetValue("boot", out boot) || string.IsNullOrWhiteSpace(boot)) { options.Settings["boot"] = "Domain"; } ResolveAssembliesFromDirectory( Path.Combine(Directory.GetCurrentDirectory(), "bin")); WriteLine("Starting with " + GetDisplayUrl(options)); IServiceProvider services = ServicesFactory.Create(); var starter = services.GetService<IHostingStarter>(); IDisposable server = starter.Start(options); WriteLine("Started successfully"); WriteLine("Press Enter to exit"); Console.ReadLine(); WriteLine("Terminating."); server.Dispose(); } } }
能夠看到,它其實和 Microsoft.AspNet.Hosting/Program.cs 中的配置代碼很類似,但不相同,Microsoft.AspNet.Hosting 是 OWIN Host 的全部概念實現,而 OwinHost 只是一個控制檯啓動程序,用來加載全部的 OWIN 組件,但它不包含任何的實現,好比 Host 中的 Builder、Server、Startup 等一些操做,再看下面一張圖就明白了:ide
對,沒錯,OwinHost 依賴於 Microsoft.Owin.Hosting,OwinHost 中全部的 Host 操做都在 Microsoft.Owin.Hosting 中進行完成了,說白了,OwinHost 沒多少東西,就是一個開啓命令,和 Microsoft.AspNet.Hosting 徹底不是一個概念問題,那 OwinHost 和 K Commands 相等嗎?其實也不相等,只是很相似,但這個相似點只是體如今加載 OWIN 組件的時候,OwinHost 的工做就是幹這個的,而且只能幹這個,而 K Commands 卻不單單如此,它還包含了其餘的一些命令管理,好比「gen」、「ef」等。ui