Create Orchard Core Website from Scratch Getting started with Orchard Core for Microsoft ASP.NET Core developers

Create Orchard Core Website From Scratch Using ASP.NET Core Empty Web Project Template

Last week I finished teaching my last Orchard Core Developer Training course for 2020. During these courses I often begin with the fundamentals of creating an Orchard Core website from scratch using the .NET Core CLI and the ASP.NET Core Empty Web Project Template. Starting this way often makes Orchard Core much more approachable to Microsoft ASP.NET Core developers. If you haven't tried this yourself, let's walk through the process of creating an Orchard Core website from scratch using the .NET Core CLI and the ASP.NET Core Empty Web Project Template. Understanding this will help you better understand the Orchard Core code generation templates as well as the sample web applications in the Orchard Core source code. The whole process takes less than 15 minutes.

Getting Started with Orchard Core

Most of our time will be spent in a terminal using the .NET Core CLI to execute simple commands. I do this on purpose, because it accentuates just how simple it is to get started with Orchard Core. So when you're ready, open a terminal and navigate to a directory where you can execute .NET Core CLI commands. Once you’re in a suitable location, create a new folder and solution, called MyWebsite, using a single command and navigate inside that folder.

dotnet new sln -o MyWebsite
cd MyWebsite

Similar to above, let's create an ASP.NET Core Empty Web Project, called Web. I like to place my source code in a src folder to keep things nice and organized, so execute the following commands to create the new web project and add this project to the solution.

dotnet new web -o src/Web
dotnet sln add src/Web/Web.csproj

Up to this point everything has been typical ASP.NET Core development. We've created a solution and an empty ASP.NET Core Web Project. Now is when we begin to add the bits to turn this ASP.NET Core Web Project into an Orchard Core CMS project.

Adding Orchard Core to the ASP.NET Core Web Project

Navigate to the web project folder and add the latest stable version of the OrchardCore.Application.Cms.Targets package to the project.

cd src/Web
dotnet add package OrchardCore.Application.Cms.Targets --version 1.0.0-*

Now we need to make 2 small changes to the Startup.cs file in the ASP.NET Core Web Project. You can modify it in any editor you choose. I will open the file in Visual Studio Code from the terminal.

code Startup.cs

Modify the file so it looks as follows.

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddOrchardCms();
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseOrchardCore();
    }
}

The code above adds the Orchard Core CMS services to the dependency injection container and Orchard Core to the middleware pipeline. Save the file and run the web project from the terminal.

dotnet run

After a few seconds, the website will be listening on ports 5000 and 5001.

Now listening on: https://localhost:5001
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

Open a browser and navigate to https://localhost:5001 to display the Orchard Core startup page and begin the setup process for your new Orchard Core CMS website.

Orchard Core CMS Website from Scratch Startup Page

Wrap Up

In this Orchard Core tutorial we created an Orchard Core CMS website from scratch using the .NET Core CLI and the ASP.NET Core Empty Web Project Template.

We added the OrchardCore.Application.Cms.Targets Nuget package to the web project and made two small modifications to the Startup.cs file to add Orchard Core CMS services to the dependency injection container and Orchard Core to the middleware pipeline.

Once those changes were made, we ran the Orchard Core web project and navigated to https://localhost:5001 to begin the setup process for our new Orchard Core CMS website.