代码之家  ›  专栏  ›  技术社区  ›  Rok

自托管vnext应用程序

  •  3
  • Rok  · 技术社区  · 10 年前

    我想知道我是否可以重构一个自托管应用程序(启动并显示其提供的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”命令定义中的类相同)。请记住,OwinStartup需要IAppBuilder,vnext需要IBuilder。

    1 回复  |  直到 10 年前
        1
  •  2
  •   Eilon    10 年前

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

    项目wiki包含有关 kpm 工具的各种选项: https://github.com/aspnet/Home/wiki/Package-Manager

    以下是的命令行帮助 kpm包装 让你知道它能做什么。

    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