Pages

Sunday, June 27, 2021

Fedora 34 : ASP.NET Core application - part 001.

This tutorial is about creating an ASP project on Fedora 34 Linux distro.
Let's create a folder for a new ASP project:
[mythcat@desk ~]$ cd CSharpProjects/
[mythcat@desk CSharpProjects]$ mkdir ASPProjects
[mythcat@desk CSharpProjects]$ cd ASPProjects/
[mythcat@desk ASPProjects]$ dotnet new web -o ASP001
The template "ASP.NET Core Empty" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on ASP001/ASP001.csproj...
  Determining projects to restore...
  Restored /home/mythcat/CSharpProjects/ASPProjects/ASP001/ASP001.csproj (in 152 ms).
Restore succeeded.
In the ASP001 folder project will run these commands:
[mythcat@desk ASPProjects]$ cd ASP001/
[mythcat@desk ASP001]$ dotnet restore
  Determining projects to restore...
  All projects are up-to-date for restore.
[mythcat@desk ASP001]$ dotnet run
Building...
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:5001
This program will show
info: Microsoft.Hosting.Lifetime[14] Now listening on: http://localhost:5000 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: /home/mythcat/CSharpProjects/ASPProjects/ASP001 ^Cinfo: Microsoft.Hosting.Lifetime[0] Application is shutting down...
This program will show on browser localhost the text: Hello World!
With the dotnet restore command, we download the necessary dependencies.
It calls into NuGet - .NET package manager to restore the tree of dependencies.
Let's see the files from this project:
[mythcat@desk ASP001]$ ls
appsettings.Development.json  ASP001.csproj  obj	 Properties
appsettings.json	      bin	     Program.cs
[mythcat@desk ASP001]$ cat Program.cs 
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Hosting;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}

app.MapGet("/", (Func<string>)(() => "Hello World!"));

app.Run();
[mythcat@desk ASP001]$ cat ASP001.csproj 
...
This is the most simple tutorial about the ASP project.