Created
March 23, 2017 20:53
-
-
Save A-Programmer/804020f47f922b8c75a0361bb70a62eb to your computer and use it in GitHub Desktop.
Creating new Empty MVC Project and run it in Visual Studio Code with Dot Net Core
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| First of all you should install pre requirements: | |
| Install Dot Net Core (http://dot.net/Core) | |
| Install Visual Studio Code | |
| 1. Now run Visual Studio Code | |
| 2. Press Ctrl + ` (or from View menu select Integrated Terminal) | |
| 3. Navigate to folder that you want to create project in it. | |
| 4. run this command : dotnet new web (this will create project files in current folder) | |
| 5. Open Startup.cs file and edit it : | |
| 5.1 Add 'services.AddMvc();' to ConfigureServices void | |
| 5.2 Add route to Configure void : | |
| app.UseMvc(routes => | |
| { | |
| routes.MapRoute( | |
| name: "default", | |
| template: "{controller=Home}/{action=Index}/{id?}"); | |
| }); | |
| 5.3 Delete last codes that are about printing Hello World message on page. | |
| 6. Now absolutely you need some packages like Microsoft.AspNetCore.Mvc and others for this opem YourProkectName.csproj | |
| 7. In ItemGroup section Add this lines : | |
| <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" /> | |
| <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" /> | |
| <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" /> | |
| <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" /> | |
| 8. It's done! | |
| ------- | |
| Now add Controllers folder to root and add HomeController.cs to Controllers folder and edit this file like this: | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Threading.Tasks; | |
| using Microsoft.AspNetCore.Mvc; | |
| namespace TestMvcApp.Controllers | |
| { | |
| public class HomeController : Controller | |
| { | |
| public IActionResult Index() | |
| { | |
| ViewData["TestData"] = "Hello World!"; | |
| return View(); | |
| } | |
| } | |
| } | |
| Add Views folder to root and add Home folder in it then add Index.cshtml in it, open this file and write this codes: | |
| My Message : @ViewData["TestData"] | |
| ***** Now you should run this command in terminal : dotnet restore | |
| ***** Bingo, Thats it. run your project by running 'dotnet run' in terminal! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment