First, create a .NET project using the appropriate command (in this tutorial, I'll name it "helloGtk"):
dotnet new console -o helloGtk
Once the folder is created, navigate into it:
cd helloGtk
The next step is to add the GTK4 NuGet packages to the project:
dotnet add package GirCore.Gtk-4.0
Note: Typo fixed from GirCore.Gtk-4.O to GirCore.Gtk-4.0 in the command above.
Next, edit the Program.cs file with the C# source code you wish to compile.
For convenience, I use a pre-made Program.cs template that I adapt to my needs each time.
After completing the steps above, I replace the project's default Program.cs file with my pre-existing one to avoid rewriting it from scratch every time.
Once the Program.cs file is replaced, I compile and run the application from inside the project directory:
dotnet run
If everything was executed correctly, a window displaying your program should appear on the screen!
Below is an example Program.cs file to test the procedure described in this tutorial: