ASP. NET 5 getting started -- create an empty project, asp.net getting started

Source: Internet
Author: User

ASP. NET 5 getting started -- create an empty project, asp.net getting started
ASP. NET 5 getting started -- create an empty project idea ¶

ASP. NET 5 RC1 has been released for a week, because it has been in the bate version, and many things will change, so it has never been written casually. From today on, I will bring you a series of ASP. NET 5 tutorials.

Create an empty project producer ¶

Although I believe that you will not create only one Empty project, it is the easiest option to use as an entry-level discussion. First, use Visual Studio 2015 to create an empty project.

Annotation

If you are using Linux/Mac OS, see Your First ASP. NET 5 Application on a Mac

Visual Studio 2015 has three options under the Web directory. Selecting the first option will enable a wizard, where ASP. NET 4.5 or ASP. NET 5 projects are optional. The next two items are to use ASP. NET 5 to create a class library and a command line program.

Select the ASP. NET 5 Empty project.

Solution directory structure ¶

After creating a project, the project folder structure is as follows:

  • Src
  • Global. json
  • {Your-solution-name}. sln

{your-solution-name}.slnThis file is used by Visual Studio to identify the entire solution. It is no different from other types of projects and will not be introduced.

Global. json plugin ¶

global.jsonFiles are used to define solution-level settings, functions, and{your-solution-name}.slnSame. So why do we need to define it again? ASP. NET 5 is designed to run on the entire platform, but does not have a powerful IDE on non-Windows platforms. It can only be solved by some text editors.{your-solution-name}.slnThe file is meaningless.global.jsonThe default file content is as follows: (the version value depends on your installed version)

123456
{  "projects": [ "src", "test" ],  "sdk": {    "version": "1.0.0-rc1-update1",  }}

projectsUsed to define the folder to which the related project belongs, that is, to find the project under which subfolders, the default includesrcFolder.sdkIndicates the SDK version used, includingversion,architecture,runtimeThree sub-items. In Windows,runtimeOptionalcoreclrAndclr(Default). Optional in Linux/Mac.coreclrAndmono(Default ). Since ASP. NET 5 starts, the default runtime is very short and almost does not contain anything. Therefore, you need to download it as a Nuget package, which is in the system folder by default (which is unknown ). We can usepackagesForcibly specify where all downloaded files are stored. The following is a complete example:

123456789
{  "projects": [ "src", "test" ],  "packages": "C:\\Program Files (x86)\\Microsoft Web Tools\\DNU",  "sdk": {    "version": "1.0.0-rc1-update1",    "architecture": "x64",    "runtime": "coreclr"  }}
Project directory structure ¶

After discussing the file structure at the solution level, let's look at the project level. First, gosrc\{your-project-name}Folder. The file directory is as follows:

  • PropertieslaunchSettings. json (available only on Windows)
  • Wwwroot
  • Wwwroot \ web. config
  • Project. json
  • Project. lock. json (rundnu restoreGenerate)
  • Dockerfile (not available on Windows)
  • {Your-project-name}. xproj (available only on Windows)
  • Startup. cs

In this case, wwwroot is the root directory of the website during runtime (you canproject.json).PropertiesFolderlaunchSettings.jsonIt can be modified through Visual Studio's graphical interface, which is not described in detail.project.lock.jsonIs based onproject.jsonFile generation. You can use the command in the project directory to generate a new file.dnu restoreComplete. Visual Studio 2015 automatically runs this command when necessary. The following focuses onproject.jsonAndStartup.csTwo files.

Project. json syntax ¶

project.jsonIt mainly includes the configuration of the project (such as the files to be compiled, the files to be stored during output, and the dependencies of the project) and the metadata of the generated dll (version number, title, author, copyright information ).

The default file is as follows (both Windows and Mac platforms ):

What is more important (commonly used in development) isdependencies,commands,frameworks.

dependenciesIt contains the reference and version of the project. Because it is an empty project, only two Web servers, IIS and Kestrel are referenced. Among them, Kestrel is a cross-platform Web server.

frameworksContains the framework to be compiled. When running on a non-Windows platform, keep only"dnxcore50":{}.

commandsSome commands indnxAvailable parameters when running the command. For examplednx webStart the Kestrel server with the default parameters (listenerHttp: // localhost: 5000You can also use the following settings to listen to ports 5000 and 5001 at the same time.

Annotation

This setting also ensures that all requests that reach 5000 and 5001 are accepted, without requiringlocalhost.

"commands":{  "web":"Microsoft.AspNet.Server.Kestrel --server.urls http://*:5000;http://*:5001"}

Of course, you can also define this line through another json file, otherwise each change needs to rundnu restoreCommand.

"commands": {  "web": "Microsoft.AspNet.Hosting  --config hosting.json",}

hosting.jsonThe file is as follows:

{  "server": "Microsoft.AspNet.Server.Kestrel",  "server.urls": "http://*:5000"}
Startup. cs restart ¶

Please refer to my other blog post ASP. NET 5 getting started -- Application Startup

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.