Build a. NET core environment on Windows systems and create a running ASP.

Source: Internet
Author: User
Tags dotnet

Microsoft officially released the. NET Core 1.0, ASP. 1.0, and Entity Framework Core 1.0 on June 27 at the Red Hat Devnation summit, which will all support Windows, OS X, and Linux operating systems. One of the most notable of the. NET Core is a cross-platform, open source, and modular model. NET platform that can be used to build Web applications, microservices, create application libraries and consoles. ASP. NET 5 has been changed from Microsoft to ASP. 1.0,.net 5, which is now known as the 1.0,EF7 (Entity Framework 7), which is the Entity Framework Core 1.0. Microsoft is going to play the big one this time, and the advent of. NET core gives me great hope for the future of. NET technology. So let's start exploring the. NET core with. NET core from. NET runtime (providing basic services such as running environment, sink code loading, garbage collection, etc.), framework library (fully integrated traditional. NET Standard library. Provides basic data types and the base components for different types of applications, etc.), the. NET Core SDK (SDK tools and language compilers for related series), and the command-line toolset for. NET core apps. build A. NET Core environment on WindowsReference Document: Https://www.microsoft.com/net/core#windows 1. Download the required filesThere are two options for the official. One is to install Visual Studio Update 3 and NET Core 1.0 for Visual Studio, and the other is to use Microsoft's own editor Visual Studio code and install the. NET Core SD K for Windows. This time choose the second way, by the way, with Visual Studio Code. Download the following two files.
2. Installing the SDK

3. Execute dotnet New command to create a sample programThe first run of dotnet new will appear as follows, waiting for 100% to complete. According to the official document, first create a folder mkdir Hwapp, then CD Hwapp into the directory, and finally dotnet New is to create a simple C # program.
The fact is that two files are created under the newly created Hwapp folder, as shown below

Opening a program.c file with VS code is a simple C # console program, and Project.json is a configuration file.
4. Running the programThen proceed to the command dotnet restore is used to fix a specific package in Project.json, and a file named Project.lock.json is generated under the Hwapp file
Execute command dotnet run, successfully typed Hello world!

Successful execution of a console application program! to create an ASP. NET Web site on WindowsReference Document: Https://docs.asp.net/en/latest/getting-started.html 1. Modify the Project.json fileAdd the code "Microsoft.AspNetCore.Server.Kestrel": "1.0.0" in the location shown below, i.e. add Kestrel HTTP Server package as a dependency 2. Run the command dotnet restoreUsed to repair packages 3. Create a Startup.cs programCreate a file named Startup.cs in the Hwapp above
Add the following code:
usingSystem;usingMicrosoft.AspNetCore.Builder;usingMicrosoft.AspNetCore.Hosting;usingMicrosoft.AspNetCore.Http;namespaceaspnetcoreapp{ Public classStartup { Public voidConfigure (Iapplicationbuilder app) {app. Run (Context=            {                returnContext. Response.writeasync ("Hello from ASP. core!");        }); }    }}
View Code 4. Modify Program.csModify the code in Program.cs as follows:
usingSystem;usingMicrosoft.AspNetCore.Hosting;namespaceaspnetcoreapp{ Public classProgram { Public Static voidMain (string[] args) {            varHost =NewWebhostbuilder (). Usekestrel (). Usestartup<Startup>()                .            Build (); Host.        Run (); }    }}
View Code


5.dotnet Run


6. Enter http://localhost:5000 in the address bar


Run successfully!

Build a. NET core environment on Windows systems and create a running ASP.

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.