- .NET Core is a free and open source cross-platform version of .NET for building websites, services, and console apps.
- The project is primarily developed by Microsoft and released under the MIT License.
- .NET Core Version 3.0.0 was released on September 23 2019.
- To use .NET Core 3.0 with Visual Studio, you need Visual Studio 2019 v16.3 or later.
In this article, I will show how to get started with .NET Core Console application and ASP.NET Core Web Application from Windows Console.
.NET Core Console Application
Step 1: Download and install the .NET SDK (Software Development Kit)
URL: https://dotnet.microsoft.com/download
Step 2: Check the software installed correctly or not by running the below command from windows console
C:\Users\Girish>dotnet
Usage: dotnet [options]
Usage: dotnet [path-to-application]
Options:
-h|--help Display help.
--info Display .NET Core information.
--list-sdks Display the installed SDKs.
--list-runtimes Display the installed runtimes.
path-to-application:
The path to an application .dll file to execute.
To see the .NET Core information run dotnet --info
Step 3: Now run the below command to create the new .NET Core console app
C:\Users\Girish>dotnet new console -o myConsoleApp
Now the console app will be created. Now go to the myConsoleApp and type dir
to see the list of files it was created.
C:\Users\Girish\myConsoleApp>dir
...........
Directory of C:\Users\Girish\myConsoleApp
04-10-2019 02:01 PM <DIR> .
04-10-2019 02:01 PM <DIR> ..
04-10-2019 02:01 PM 178 myConsoleApp.csproj
04-10-2019 02:01 PM <DIR> obj
04-10-2019 02:01 PM 194 Program.cs
.............
Step 4: Now type the below command to run the program
C:\Users\Girish\myConsoleApp>dotnet run
Hello World!
Step 5: Let us modify the Program.cs
code as below and run the program once again. Update the code as shown below
using System;
namespace myConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to .Net Core Hello World! Console Application");
}
}
}
Now save the file and run the application once again from command prompt.
C:\Users\Girish\myConsoleApp>dotnet run
Welcome to .Net Core Hello World! Console Application
ASP.NET Core Web Application
Step 1: Run the below code to create the application
C:\Users\Girish\>dotnet new webApp -o myNewWebApp --no-https
- The
webApp
parameter selects what template to use when creating your app. - The
-o
parameter creates a directory named myWebApp where your app is stored. - The
--no-https
flag specifies not to enable HTTPS.
Step 2: To see the list of files created, enter the dir
command as show below
C:\Users\Girish\myNewWebApp>dir
.....................
Directory of C:\Users\Girish\myNewWebApp
04-10-2019 02:11 PM <DIR> .
04-10-2019 02:11 PM <DIR> ..
04-10-2019 02:07 PM 146 appsettings.Development.json
04-10-2019 02:07 PM 192 appsettings.json
04-10-2019 02:11 PM <DIR> bin
04-10-2019 02:07 PM 183 myNewWebApp.csproj
04-10-2019 02:11 PM <DIR> obj
04-10-2019 02:07 PM <DIR> Pages
04-10-2019 02:07 PM 719 Program.cs
04-10-2019 02:07 PM <DIR> Properties
04-10-2019 02:07 PM 1,445 Startup.cs
04-10-2019 02:07 PM <DIR> wwwroot
......................
Step 3: Now type the below command to run the application
C:\Users\Girish\myNewWebApp>dotnet run
Now the application is hosted locally and use http://localhost:5000/
in the browser to see the application
Step 4: Update the code inside the file myNewWebApp\Pages\Index.cshtml
and Add the below h1 tag code inside the div tag
<h1> Welcome to ASP.NET Core Web Application </h1>
Step 5: Now save and run the application once again. Press Ctrl + C
to shutdown the application
References
- https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/intro
- https://dotnet.microsoft.com/learn/aspnet/hello-world-tutorial/intro
- https://dotnet.microsoft.com/download
Learn more about .NET Core features in our upcoming blog articles.
Happy Learning!