Download and run the .Net 6.0 SDK installer found here: https://dotnet.microsoft.com/download/dotnet/
2. Testing the Installation
To check the installation is working open a command prompt an run this command:
Code: Select all
dotnet -?
Code: Select all
.NET SDK (6.0.100)
Usage: dotnet [runtime-options] [path-to-application] [arguments]
Run this command to list the types of projects available:
Code: Select all
dotnet new --list
Code: Select all
These templates matched your input:
Template Name Short Name Language Tags
-------------------------------------------- ------------------- ---------- -------------------------------------
ASP.NET Core Empty web [C#],F# Web/Empty
ASP.NET Core gRPC Service grpc [C#] Web/gRPC
ASP.NET Core Web API webapi [C#],F# Web/WebAPI
ASP.NET Core Web App razor,webapp [C#] Web/MVC/Razor Pages
ASP.NET Core Web App (Model-View-Controller) mvc [C#],F# Web/MVC
ASP.NET Core with Angular angular [C#] Web/MVC/SPA
ASP.NET Core with React.js react [C#] Web/MVC/SPA
ASP.NET Core with React.js and Redux reactredux [C#] Web/MVC/SPA
Blazor Server App blazorserver [C#] Web/Blazor
Blazor WebAssembly App blazorwasm [C#] Web/Blazor/WebAssembly/PWA
Class Library classlib [C#],F#,VB Common/Library
Console App console [C#],F#,VB Common/Console
...
Code: Select all
md MyWebApp
cd MyWebApp
dotnet new mvc
To build and run this project just run this command fom inside the project MyWebApp folder:
Code: Select all
dotnet run
Code: Select all
Building...
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:7121
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5118
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: D:\Training\.NetCore\MyWebApp\
5. Running the New Project Using Watch
To build and run this project using the watch option run this command fom inside the project MyWebApp folder:
Code: Select all
dotnet watch
Code: Select all
watch : Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload. Press "Ctrl + R" to restart.
watch : Building...
Determining projects to restore...
All projects are up-to-date for restore.
MyWebApp -> D:\Training\.NetCore\MyWebApp\bin\Debug\net6.0\MyWebApp.dll
watch : Started
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:7121
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5118
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: D:\Training\.NetCore\MyWebApp\
This can also be seen by the output message produced when that file is detected:
Code: Select all
watch : File changed: D:\Training\.NetCore\MyWebApp\Views\Home\Index.cshtml.
watch : Hot reload of changes succeeded.
As you start to develop you'll want to add packages to your project. For example assume you would like to use the Newtonsoft.Json package in your code.
In your code you'll need to add a using statement as shown below:
Code: Select all
using Newtonsoft.Json;
As hinted by the error message the project is missing an assembly reference to the Newtonsoft.Json package.error CS0234: The type or namespace name 'Json' does not exist in the namespace 'Newtonsoft' (are you missing an assembly reference?)
To fix this run the following command line command:
Code: Select all
dotnet add package Newtonsoft.Json
7. HTTPS Certificate Issues
When trying to load the application in the Web browser, the following error might be generated:
To fix this issue run these commands:AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot
Code: Select all
dotnet dev-certs https --clean
dotnet dev-certs https
dotnet dev-certs https --trust