Let's start by building a simple "Hello, world!" app.
-
1
Install .NET Core. See installation steps for Windows, macOS, and Linux here.
-
2
Create a new .NET Core project:
- mkdir aspnetcoreapp
- cd aspnetcoreapp
- dotnet new web
-
3
Restore the packages
- dotnet restore
-
4
Update the code in Startup.cs to return a message of our choice
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.Run(async (context) => { await context.Response.WriteAsync("Hello from ASP.NET Core!"); }); } -
5
Run the app (the dotnet run command will build the app when it's out of date)
- dotnet run
-
6
Browse to http://localhost:5000
-
7
Press Ctrl+C to stop the app
Now let's enable support for static files.
-
1
Add the static file middleware in Startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseStaticFiles(); app.Run(async (context) => { await context.Response.WriteAsync("Hello from ASP.NET Core!"); }); } -
2
Add the static file middleware NuGet package
- dotnet add package Microsoft.AspNetCore.StaticFiles
- dotnet restore
-
3
Add index.html file to the wwwroot folder
<!DOCTYPE html> <html> <body> <h1>Static file from ASP.NET Core!</h1> </body> </html> -
4
Build and run the app
- dotnet run
-
5
Browse to http://localhost:5000/index.html
-
That’s it!
Next up, try building your first ASP.NET Core MVC app with Visual Studio or Visual Studio Code.