Asp.net core development environment preparation, asp. netcore

Source: Internet
Author: User

Asp.net core development environment preparation, asp. netcore

Reference page:

Http://www.yuanjiaocheng.net/ASPNET-CORE/core-authorize-attribute.html

Http://www.yuanjiaocheng.net/ASPNET-CORE/core-identity-configuration.html

Http://www.yuanjiaocheng.net/ASPNET-CORE/core-identity-migrations.html

Http://www.yuanjiaocheng.net/ASPNET-CORE/core-user-registration.html

Http://www.yuanjiaocheng.net/ASPNET-CORE/core-add-user.html

1.1 install sdk and run

The browser opens the Web https://www.microsoft.com/net/download to the. Net Core download page.

Download the corresponding SDK for installation Based on the operating system. After installation, you can run the dotnet command from the command line to check whether the installation is successful.

1.2 use VS2015

First make sure that Visual Studio 2015 Update3 is installed on your computer, of course we can also install Visual Studio Community 2015 (https://www.visualstudio.com/products/visual-studio-community-vs) to replace paid Visual Studio 2015.

VS2015: https://www.visualstudio.com/zh-cn/downloads/download-visual-studio-vs.aspx

Then to https://go.microsoft.com/fwlink? LinkId = 817245 download "NET Core Tooling Preview 2 for Visual Studio 2015"

Open VS2015.

Create a project and select Asp.net Core Application project.

After configuring the location of the project file, click OK, select a template, and verify the identity.

Click OK to generate the project.

There are two options for starting debugging:

Use IIS Express as the host or select the Application self-host mode. The effect is as follows:

1.3 Use VSCode (cross-platform solution)

The general cross-platform solution is to use Visual Studio Code, we first go to https://code.visualstudio.com/download VS Code for installation.

 

After installation, Open VS Code, Ctrl + P Open Quick Open, enter the following command to install C # for Visual Studio Code.

Ext install csharp

After the installation is successful, restart VS Code.

Next we will create a new folder to test Asp.net Core.

Go to the folder and run the following commands on the command line:

Dotnet new-t web

Dotnet restore

Dotnet run

Now open http: // localhost: 5000 in the browser and you can see the site generated by default.

Run "CTRL + C" on the command line to end the test. Next we use VS Code to open the project folder. The generated content is as follows:

 

Right-click and use VS Code to open the folder.

At this time, we will remind you to download the debugging and compilation tools and click "Yes ".

Note the following status bar information, but note that if the download fails, you may need to consider proxy or other scientific methods to access the Internet.

Fortunately, the download and installation are successful.

Expand the debugging function.

If no matching exists in the debugging options, select. NET Core from the configuration drop-down list.

Select a web project in the debugger.

Start debugging.

If you open a project created in VS2015, the following error may occur:

Open launch. json and modify the program path. You can view the content in the compiled bin/debug Folder:

Start debugging. After compilation is successful, the browser is automatically started.

However, the style we see is different from that we can see from the command line. The reason is that the debugging mode is different from the Product mode, and the file used is different. We can see the reason in the _ Layout file.

In development mode, the referenced bootstrap file is under the "wwwroot/lib/bootstrap" directory, but we cannot find this directory currently. The JQuery and Bootstrap dependencies of the project are installed through bower, which can be seen from bower. json.

It seems that you need to install bower first. Run the following command to install it:

Npm install-g bower

If you don't even have npm, install node first. Here, I will not continue to worry about it.

Run

Bower install

Install dependencies.

Start debugging again.

Now everything is normal.

To debug the code, click the breakpoint on the left side of the Code.

1.4 Yeoman

During Asp.net Core development using VS Code, we usually use Yeoman and VS Code for cooperation. Yeoman is a set of tools that generate a project file for Asp.net Core by means of a template, and generate a separate file such as Contoller and View.

First, we install a complete set of dependencies through NPM.

Npm install-g yo bower grunt-cli gulp

Then run the following command to install generator-aspnet.

Npm install-g generator-aspnet

Next we will re-start building an Asp. Net Core project.

Create a folder for the test project.

Run

Yo aspnet

Check whether statistics can be uploaded.

The options for creating a project are as follows:

Use the keyboard up and down keys to select, and then press enter to confirm. Here I create a Basic web project.

Next I chose to use the UI framework, and I chose Bootstrap.

 

Enter the name of the project to be created (BasicWeb ).

Now we are prompted that the creation is successful. The restore, build, and run commands of dotnet are used to load dependencies, compile, and run.

Now you can use VS Code to open the folder and edit and debug it.

When you open the SDK for the first time, you will still be prompted to click yes to generate the. vscode folder. The configuration files related to compilation and startup will be generated below.

 

Add Controller

Open the Controller folder from the command line in VS Code.

Run the following command:

Yo aspnet: MvcController DemoController

Return to vscode to view the generated file.

Then generate the corresponding view File.

Add View

Now you can create a Demo1 folder in the Views folder to correspond to the Demo1Controller.

Open the Demo1 folder from the command line and execute the following command to create the Index View File.

Yo aspnet: MvcView Index

Conclusion 1.5

Taking advantage of the Dongfeng release of. NET Core 1.0, I wrote such an entry-level article (I found that I have been writing entry-level articles for a limited number of times ). Driven by the Irreversible Wave of open source, there is reason to believe that. NET Core will grow better and better. I will share more and better original blog posts on this aspect with you. Let's work together.

Finally, we should remind you that "dotnet restore" should be run no matter how the project is created and before the VSCODE is opened ". Of course, in a cross-platform development environment, you must be familiar with the various commands of dotnet cli and leave the giants like VS2015. The command line is the most practical in linux and Mac.

 

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.