In this section, thought of getting started new series on ASP.NET Core stuffs right from the beginning. The very first thing which needs to be done here downloading the core components from http://dot.net. Here, you will get two options LTS(Long Term Solution) and Current. I prefer LTS as this is how it is going to be in future. The major difference which I see is Project Type System (.xproj –> .csproj) change and project.json is going away. This has been done to embrace the existing Microsoft ecosystem which is based on .csproj system.
Tooling which I will be using here is Visual Studio Code and Visual Studio 2017. Both you can download from http://visualstudio.com/.
Hence, without wasting time let’s get started. I will create dotnet web app using CLI and marking the same as web project rather than Console project. Below is the command for the same.
Here, -t is type, which I am marking as web. By default, it creates a console app. With that being said, it will drop all web related assets in the folder. After that I will do dotnet restore.
Now, let’s go ahead and do dotnet build just to build the project. Once, build succeeded, then we can go ahead and do dotnet run. Although, build is not necessary as while running dotnet run, it will automatically build the project as well like in visual studio.
At this stage my application is running fine and I can now switch to browser @ http://localhost:5000. Once, I do so, it will present me full fledged MVC App as shown below.
Let’s open the project in code now with code . command. This will open code in the same project context. This is how my typical web app looks like.
I can also go ahead and configure code as my debugger like we do with visual studio. Here, first I will go ahead and type “ctrl+shift+B“, this will give me options to configure the task runner.
Here, I will click on Configure Task Runner option. This will present me below options.
From here, I will select .NET Core. Upon doing so, it will drop one tasks.json file like shown below.
Now, I can go ahead and build the solution from code itself using “ctrl+shift+B” command and it will build fine without any errors like shown below.
At this moment, I cannot run this app from code as I have not configured the same. In order to do so, I need to little configuration like, I need to click on debugger icon as highlighted below.
Then, we need to click on this little gear icon as shown below.
Upon clicking the same, it will again present me environment options as shown below.
From here, we will select .NET Core off-course. Upon doing so, it will create one new launch.json file as shown below.
Here, we need to modify couple of things like framework and application name. Below is the finished launch.json file in finished format.
Here, you can see that under program section, I have modified the framework and application.dll section. With this change in place, when we go ahead do “ctrl+f5“, it will launch the application from terminal like shown below.
Therefore, here we are running the app from visual studio code. This was just the beginners’ guide around ASP.NET Core; we will delve further in coming section around the new changes in ASP.NET Core and Core concepts of MVC.
2,094 total views, 2 views today