【问题标题】:self hosted vnext application自托管 vnext 应用程序
【发布时间】:2014-08-20 11:39:36
【问题描述】:

我想知道是否可以重构一个自托管应用程序(启动并显示它提供的 Web 服务的 URL 的控制台应用程序),使其在纯 vnext 而不是 owin 上工作。

owin代码如下

namespace Selfhostingtest
{
    class Program
    {
        static void Main(string[] args)
        {
            String strHostName = string.Empty;
            strHostName = Dns.GetHostName();
            Console.WriteLine("Local Machine's Host Name: " + strHostName);
            var options = new StartOptions();
            IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
            IPAddress[] addr = ipEntry.AddressList;
            for (int i = 0; i < addr.Length; i++)
            {
                if (!addr[i].IsIPv6LinkLocal && addr[i].AddressFamily == AddressFamily.InterNetwork)
                {
                    Console.WriteLine("IPv4 Address {0}: {1} ", i, addr[i].ToString());
                    options.Urls.Add(String.Format("http://{0}:5000/", addr[i].ToString()));
                }
            }
            using (WebApp.Start<Startup>(options))
            {
                Console.WriteLine("Razor server is running. Press enter to shut down...");
                Console.ReadLine();
            }
        }
    }
}

为了记录,我不想使用“k web”命令行启动。我想将 vnext 应用程序完全打包为可执行文件。

应使用 Microsoft.AspNet.Hosting 而不是 Microsoft.Owin.Hosting(与“k web”命令定义中的类相同。请记住,Owin Startup 需要 IAppBuilder,而 vnext 需要 IBuilder。

【问题讨论】:

标签: self-hosting asp.net-core


【解决方案1】:

在 ASP.NET vNext 中,您无法构建 EXE 文件,但您绝对可以将应用程序打包成独立的。查看可以在应用文件夹中运行的 kpm pack 命令。它将打包所有依赖项并生成您可以使用的命令脚本(而不是使用k web 等)。最后,如果你看看 k web 做了什么,它只是一些 shell 脚本,它们最终运行 klr.exe 并带有各种参数来指示它应该开始什么。

项目 wiki 有一些关于 kpm 工具的各种选项的基本信息:https://github.com/aspnet/Home/wiki/Package-Manager

这里是kpm pack 的命令行帮助,让您了解它的功能。

Usage: kpm pack [arguments] [options]

Arguments:
  [project]  Path to project, default is current directory

Options:
  -o|--out <PATH>                  Where does it go
  --configuration <CONFIGURATION>  The configuration to use for deployment
  --overwrite                      Remove existing files in target folders
  --no-source                      Don't include sources of project dependencies
  --runtime <KRE>                  Names or paths to KRE files to include
  --appfolder <NAME>               Determine the name of the application primary folder
  -?|-h|--help                     Show help information

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-19
    • 2015-01-29
    • 1970-01-01
    相关资源
    最近更新 更多