Code Generation TemplatesLink

Orchard Core Templates uses dotnet new templates configurations for creating new websites, themes and modules from the command shell.

More information about dotnet new can be found at https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-new

Installing the Orchard Cms templatesLink

Once the .NET Core SDK has been installed, type the following command to install the templates for creating Orchard Core Cms web applications.

dotnet new -i OrchardCore.Cms.Templates::1.0.0-beta2-*

This will use the most stable release of Orchard Core. In order to use the latest dev branch of Orchard Core, the following command can be used:

dotnet new -i OrchardCore.Cms.Templates::1.0.0-beta2-* --nuget-source https://www.myget.org/F/orchardcore-preview/api/v3/index.json  

Create a new websiteLink

From Command Shell (automated way)Link

Generate an Orchard Cms Web ApplicationLink

dotnet new occms  

Logging can be ignored with this command:

dotnet new occms --nlog false

From Visual Studio (manual way)Link

Fire up Visual Studio, create a new solution file (.sln) by creating a new ASP.NET Core Web Application :

image

Now that we created a new Web Application we need to add proper dependencies so that this new Web Application be targetted as an Orchard Core application.

See Adding Orchard Core Nuget Feed

image

Finally we will need to register Orchard CMS service in our Startup.cs file like this :

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

namespace MyNewWebsite
{
    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOrchardCms();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseOrchardCore();
        }
    }
}

Create a new moduleLink

New module from Command Shell (automated way)Link

Module commandsLink

dotnet new ocmodule -n ModuleName.OrchardCore

dotnet new ocmodule -n ModuleName.OrchardCore --PartName TestPart

dotnet new ocmodule -n ModuleName.OrchardCore --PartName TestPart --AddPart true

New module from Visual Studio (manual way)Link

Fire up Visual Studio, open Orchard Core solution file (.sln), select OrchardCore.Modules folder, right click and select "add --> new project" and create a new .NET Standard Class Library:

image

For marking this new Class Library as an Orchard Module we will now need to reference OrchardCore.Module.Targets Nuget package.

See adding Orchard Core Nuget Feed

Each of these "*.Targets" Nuget packages are used to mark a Class Library as a specific Orchard Core functionality. OrchardCore.Module.Targets is the one we are interested in for now. We will mark our new Class Library as a module by adding OrchardCore.Module.Targets as a dependency. For doing so you will need to right click on MyModule.OrchardCore project and select "Manage Nuget Packages" option. To find the packages in Nuget Package Manager you will need to check "include prerelease" and make sure you have Orchard Core feed that we added earlier selected. Once you have found it click on the Install button on the right panel next to Version : Latest prerelease x.x.x.x

image

Once done your new module will look like this :

image

For Orchard Core to identify this module it will now require a Manifest.cs file. Here is an example of that file:

using OrchardCore.Modules.Manifest;

[assembly: Module(
    Name = "TemplateModule.OrchardCore",
    Author = "The Orchard Team",
    Website = "http://orchardproject.net",
    Version = "0.0.1",
    Description = "Template module."
)]

For this module to start we now will need to add a Startup.cs file to our new module. See this file as an example:
OrchardCore.Templates.Module/Startup.cs

Last step is to add our new module to the OrchardCore.Cms.Web project as a reference for including it as part as our website modules. After that, you should be all set for starting building your custom module. You can refer to our template module for examples of what's basically needed normally.

Create a new themeLink

New theme From Command Shell (automated way)Link

Theme commandsLink

dotnet new octheme -n "ThemeName.OrchardCore"

New theme from Visual Studio (manual way)Link

Should be the same procedure as with modules but instead we need to reference OrchardCore.Theme.Targets and Manifest.cs file slightly differ:

using OrchardCore.DisplayManagement.Manifest;

[assembly: Theme(
    Name = "TemplateTheme.OrchardCore",
    Author = "The Orchard Team",
    Website = "https://orchardproject.net",
    Version = "0.0.1",
    Description = "The TemplateTheme."
)]

Adding Orchard Core Nuget FeedLink

In order to be able to use the dev feed from Visual Studio, open the Tools menu under Nuget Package Manager --> Package Manager Settings. The feed url is https://www.myget.org/F/orchardcore-preview/api/v3/index.json

image