Installing and Using the .Net 6.0 SDK

Find Tips and tricks on how to better use the Zeus IDE. Feel free to post your own tips but please do not post bug reports, feature requests or questions here.
Post Reply
jussij
Site Admin
Posts: 2498
Joined: Fri Aug 13, 2004 5:10 pm

Installing and Using the .Net 6.0 SDK

Post by jussij »

1. Download and Installation
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 -?
This showld result in the following output:

Code: Select all

.NET SDK (6.0.100)
Usage: dotnet [runtime-options] [path-to-application] [arguments]
3. Creating a New Project
Run this command to list the types of projects available:

Code: Select all

dotnet new --list
This will produce the following output:

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
...
In this case we'll create a MVC Web App using these commands:

Code: Select all

md MyWebApp
cd MyWebApp
dotnet new mvc
4. Running the New Project
To build and run this project just run this command fom inside the project MyWebApp folder:

Code: Select all

dotnet run
This will result in this output:

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\
To see the application open either of the two URLs shown in the output above.

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
That will result in this output:

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\
To see this 'hot reload' feature in action make a change to the Index.cshtml file and those those changes will be automatically applied to the running Web application.

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.
6. Adding Assemblies References to the Project
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;
However, when that code is compiled the following error will be generated:
error CS0234: The type or namespace name 'Json' does not exist in the namespace 'Newtonsoft' (are you missing an assembly reference?)
As hinted by the error message the project is missing an assembly reference to the Newtonsoft.Json package.

To fix this run the following command line command:

Code: Select all

dotnet add package Newtonsoft.Json
That will add the package to the project and the compile will the run without error.

7. HTTPS Certificate Issues
When trying to load the application in the Web browser, the following error might be generated:
AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot
To fix this issue run these commands:

Code: Select all

dotnet dev-certs https --clean
dotnet dev-certs https
dotnet dev-certs https --trust
Then restart the application and reload the Web page.
Post Reply