[Web]Get Start ASP.NET Core Quickly

Steps to create a new ASP.NET Core Sample

  1. Install dotnet core
    Download and install needed tool and package here: https://www.microsoft.com/net

  2. Run a hello world DotNet Core application
    After you have successfully installed required tools and updates. Create a folder for your first .NET Core project. Open console, navigate to the new created folder. (if you are using VS Code, simply press Ctrl+Shift+C). Run commends:

    1. dotnet new
      This command creates 2 base files.

    2. dotnet restore
      This command automatically prepare dlls from nuget

    3. dotnet run
      Run your first project. Done

  3. Add ASP.NET Core dependency
    Add "Microsoft.AspNetCore.Server.Kestrel": "1.0.0" to dependencies list of project.json file.

     "dependencies": {
         "Microsoft.AspNetCore.Server.Kestrel": "1.0.0"
     },
    
  4. Then, run dotnet restore to get additionally asp.net core dlls

    1. Add some code to build a web server
      Replace hello world code with the follow code in the Main method:

       public static void Main(string[] args)
       {
           var host = (new WebHostBuilder())
                       .UseKestrel()
                       .UseStartup<Startup>()
                       .Build();
           host.Run();
       }
      
    2. Add a new cs file named: Startup.cs

       using System;
       using Microsoft.AspNetCore.Builder;
       using Microsoft.AspNetCore.Http;
       public class Startup
       {
           public void Configure(IApplicationBuilder app)
           {
               app.Run(async (context) =>
               {
                   await context.Response.WriteAsync(
                       "Hello World. The Time is: " +
                       DateTime.Now.ToString("hh:mm:ss tt"));
               });
           }
       }
      
    3. Run dotnet restore again

  5. Test your work
    Run dotnet run , then click http://localhost:5000/

Note:

Change the "\" to "//" in tasks.json file, or you won't able to debug it in Mac OS

Example: From

"args": [
    "${workspaceRoot}\\project.son"
],

To

"args": [
    "${workspaceRoot}//project.json"
],

blog comments powered by Disqus