Vnext standalone application

I was wondering if I could refactor the self-serving application (the console application that starts and displays the URL of the web services it provides) so that it runs on a pure vnext instead of owin.

Owin code is as follows

namespace Selfhostingtest
{
    class Program
    {
        static void Main(string[] args)
        {
            String strHostName = string.Empty;
            strHostName = Dns.GetHostName();
            Console.WriteLine("Local Machine 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();
            }
        }
    }
}

      

For the record, I don't want to use the command line start "k web". I want to completely package my vnext application as an executable.

Use Microsoft.AspNet.Hosting instead of Microsoft.Owin.Hosting (same class as in the definition of the "k web" command. Note that Owin Startup expects IAppBuilder and vnext to expect IBuilder.

+3


source to share


1 answer


In ASP.NET vNext, you cannot create an EXE file, but you can definitely package your application to be standalone. Check out the command kpm pack

you can run in your application folder. It will package all dependencies as well as generate command scripts that you can use (instead of using k web

, etc.). Ultimately, if you look at what it does k web

, these are just some shell scripts that are run klr.exe

with various parameters to indicate where to start.

The project wiki has basic information about the tool kpm

for various options: https://github.com/aspnet/Home/wiki/Package-Manager



Here's a command line hint kpm pack

to give you an idea of ​​what it can do.

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

      

+2


source







All Articles