I. Create an empty Project
Please see the new. NET Core project--Hello world! section, Create a new project:
Two. Add references and modify the configuration to MVC
Modify The. Vscode\launch.json File
The code is as Follows:
1 {2"version": "0.2.0",3"configurations": [4 {5"name": ". NET Core Launch (web)",6"type": "coreclr",7"request": "launch",8"prelaunchtask": "build",9"program": "${workspaceroot}\\bin\\debug\\netcoreapp1.0\\webappcore.dll",Ten"args": [], one"cwd": "${workspaceroot}", a"stopatentry":false, -"internalconsoleoptions": "openonsessionstart", -"env": { the"aspnetcore_environment": "development" - }, -"sourcefilemap": { -"/views": "${workspaceroot}/views"//used to compile cshtml + } - } + ] a}
Launch.json
Modify The. Vscode\tasks.json File
The code is as Follows:
1 {2"version": "0.1.0",3"command": "dotnet",4"isshellcommand":true,5"args": [],6"tasks": [7 {8"taskname": "build",9"args": [Ten"${workspaceroot}\\project.json" one ], a"isbuildcommand":true, -"problemmatcher": "$msCompile" - } the ] -}
Tasks.json
Modify the Project.json project file
The Code below, Note the necessary dependencies for adding items to Microsoft's new MVC library file :
1 {2"dependencies": {3"Microsoft.NETCore.App": {//Multi-Platform compilation, the. NET core must be specified here4"version": "1.0.1",5"type": "platform"6 },7"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",8"Microsoft.AspNetCore.Mvc": "1.0.1",9"Microsoft.AspNetCore.Razor.Tools": {Ten"version": "1.0.0-preview2-final", one' Type ': ' build ' a }, -"Microsoft.AspNetCore.Routing": "1.0.1", -"Microsoft.AspNetCore.Server.Kestrel": "1.0.1" the }, - -"tools": { -"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final" + }, -"frameworks": { +"netcoreapp1.0": { a"imports": [ at"dotnet5.6" - ] - } - }, -"buildoptions": { -"emitentrypoint":true, in"preservecompilationcontext":true - }, to"runtimeoptions": { +"configproperties": { -"System.GC.Server":true the } * } $}
Project.json
Add Startup.cs File
The code follows, noting the configureservices and Configure methods in the code :
1 usingMicrosoft.AspNetCore.Builder;2 usingMicrosoft.Extensions.Configuration;3 usingMicrosoft.Extensions.DependencyInjection;4 5 6 namespaceWebappcore7 {8 public classStartup9 {Ten publicIconfigurationroot Configuration {Get; } one a publicStartup () - { -Configuration =NewConfigurationbuilder (). Build (); the } - - //the method used by the Runtime. - //Use this method to add a service to the Container. + public voidconfigureservices (iservicecollection services) - { + Services. Addapplicationinsightstelemetry (Configuration); a Services. ADDMVC (); at - } - - //the method used by the Runtime. - //Use this method to configure the Http request Pipeline. - public voidConfigure (iapplicationbuilder App) in { -App. Usemvc (routes = to { + Routes. MapRoute ( -Name"default", theTemplate"{controller=helloworld}/{action=index}/{id?}"); * }); $ }Panax Notoginseng } -}
Startup.cs
Modify the Program.cs file
The code below sets up the Host in the code :
1 usingsystem.io;2 usingMicrosoft.AspNetCore.Hosting;3 4 namespaceWebappcore5 {6 public class program7 {8 public Static voidMain (string[] Args)9 {Ten varHost =NewWebhostbuilder () one . Usekestrel () a . Usecontentroot (directory.getcurrentdirectory ()) -. Usestartup<startup>() - . Build (); the - Host. Run (); - } - } +}
Program.cs
Three. Add Controller/view
Eat at noon, continue later ~ ~
Four. run with Visual Studio Code
New asp. net Core MVC Project--Hello world!