Follow resources [3] and [4] for getting installation going (installation example above is for MacOS).
Afterwards, run dotnet
to confirm things are working. If nothing happens after installation, ensure you have followed resource [4] to symlink the installation to your path (or add the folder to path).
We simply run the following to start a new console app.
The following creates new app of type console into the myApp
folder:
dotnet new console -o myApp cd myApp
The above code will also generate a file named Program.cs
into myApp
, along with myApp.csproj
config for library usage and an obj
folder.
// Program.cs using System; namespace myApp { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } }
If we now fire dotnet run
from the command line, we will see our Hello World!
response. Hooray!
Moving further, we could add more lines into our Main
program like Console.WriteLine("The current time is " + DateTime.Now);
to update what we get.
The following initialises a web application in the folder myWebApp
:
# note that we are specifying not to enable https in this particular instance dotnet new webApp -o myWebApp --no-https
Several files were created in the myWebApp directory, to give you a simple web application that is ready to run.
Startup.cs
contains all the settings and configurations.myWebApp/Pages
directory contains some example web pages for the application.myWebApp.csproj
defines what libraries are referenced etc.If we run dotnet run
we will have a local development environment open up at port 5000
.
Editing Pages/Index.cshtml
with the following will edit the application to show the server time:
@page @model IndexModel @{ ViewData["Title"] = "Home page"; } <div class="text-center"> <h1>Hello, world!</h1> <p>The time on the server is @DateTime.Now</p> </div>