Use Visual Studio Code to Develop Asp. Net Core WebApi learning notes (1) -- start, webapi learning notes

Source: Internet
Author: User
Tags dotnet

Use Visual Studio Code to Develop Asp. Net Core WebApi learning notes (1) -- start, webapi learning notes

This document describes how to install Visual Studio Code development tools,. Net Core 1.0 SDK, and develop a simple Web-Demo website in Windows.

1. Install Visual Studio Code

Installation File: VS Code. The latest version is 1.3.

We recommend that you install the latest version. With the Debug plug-in, you can perform breakpoint debugging on vs code.

 

Ii. Install. Net Core 1.0 SDK

Installation File:. Net Core SDK

 

3. Create a. Net Core application

1. Open the cmd window and create a directory as the project directory

2. Go to the directory and run the following three commands to initialize a. Net Core application and run it.

dotnet newdotnet restoredotnet run

The running result is as follows. When Hello World! The application has been initialized successfully.

 

4. Use Visual Studio Code to compile a simple Web-Demo program

1. Use VS Code to open the folder created in the previous two steps

2. Open the project. json file and change the content to the following code snippets.

 1 { 2   "version": "1.0.0-*", 3   "buildOptions": { 4     "debugType": "portable", 5     "emitEntryPoint": true 6   }, 7   "dependencies": { 8     "Microsoft.NETCore.App": { 9       "type": "platform",10       "version": "1.0.0"11     },12     "Microsoft.AspNetCore.Server.Kestrel": "1.0.0"13   },14   "frameworks": {15     "netcoreapp1.0": {16       "imports": "dnxcore50"17     }18   }19 }

3. Execute the dotnet restore command in the cmd window to update the nuget package

4. Create the Startup. cs file and write the following content:

 1 using Microsoft.AspNetCore.Builder; 2 using Microsoft.AspNetCore.Hosting; 3 using Microsoft.AspNetCore.Http; 4  5 namespace WebApiFrame 6 { 7     public class Startup 8     { 9         public void Configure(IApplicationBuilder app)10         {11             app.Run(context =>12             {13                 return context.Response.WriteAsync("Hello World!");14             });15         }16     }17 }

5. Open the Program. cs file and change the content to the following code snippets.

using Microsoft.AspNetCore.Hosting;namespace WebApiFrame{    public class Program    {        public static void Main(string[] args)        {            var host = new WebHostBuilder()                .UseKestrel()                .UseStartup<Startup>()                .Build();            host.Run();        }    }}

 

5. Run and debug the Web-Demo Application

1. Switch to the debugging window and initialize the debugging configuration file.

Initialize the launch. json configuration file

Modify the content of the launch. json File

Initialize the tasks. json configuration file

When debugging is started for the first time, you need to configure the task running program to generate the task. json configuration file.

 

6. Start debugging

Start debugging again and the program runs normally. You can view the log output in the debugging console.

Default access path: http: // localhost: 5000. The Hello World page is displayed!

 

At this point, a simple Web-Demo application has been completed.

 

Explanation:

1. The Microsoft. AspNetCore. Server. Kestrel package encapsulates a lightweight Http Server called Kestrel, so that Web applications can be deployed and run without IIS.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.