Skip to content

Orchard provides a command-line interface for performing many of the functions that are available from the admin panel (and some that aren't). The command-line tool is named "orchard.exe" and is located in the bin directory underneath to root of your site. To run the command-line tool, first open a command prompt on the root of the site (i.e. Orchard.Web). This can be done for example by SHIFT+right-clicking on the folder in Windows Explorer and choosing "Open command window here". From there, type "bin\orchard.exe". Note that you need to run this tool from the root of your site.

Orchard提供了一个命令行界面,用于执行管理面板中提供的许多功能(以及一些不可用的功能)。命令行工具名为“orchard.exe”,位于站点根目录下的bin目录中。要运行命令行工具,首先在站点的根目录(即Orchard.Web)上打开命令提示符。这可以通过SHIFT +右键单击Windows资源管理器中的文件夹并选择“在此打开命令窗口”来完成。从那里,键入“bin \ orchard.exe”。请注意,您需要从站点的根目录运行此工具。

Using Commands

使用命令

To view a list of available commands, type "help commands" at the prompt.

要查看可用命令列表,请在提示符下键入“help commands”。

If you run Orchard.exe before you have set up your site, the only command you can run is the setup command. This performs exactly the same function as running Orchard in the browser and completing the setup form (to enter a site name, admin user name, password, and database options). Additionally, the setup command takes an optional argument, which is a list of features to enable at setup-time.

如果在设置站点之前运行Orchard.exe,则可以运行的唯一命令是setup命令。这与在浏览器中运行Orchard和完成设置表单(输入站点名称,管理员用户名,密码和数据库选项)的功能完全相同。此外,setup命令采用可选参数,该参数是在设置时启用的功能列表。

After running the setup command, you can type "help commands" again to reveal more commands.

运行setup命令后,可以再次键入“help commands”以显示更多命令。

orchard> help commands

List of available commands:

---------------------------



blog create /Slug:<slug> /Title:<title> /Owner:<username> [/MenuText:<menu text>]

        Creates a new Blog



blog import /Slug:<slug> /FeedUrl:<feed url> /Owner:<username>

        Import all items from <feed url> into the blog at the specified <slug>



cultures get site culture

        Get culture for the site



cultures list

        List site cultures



cultures set site culture <culture-name>

        Set culture for the site



feature disable <feature-name-1> ... <feature-name-n>

        Disable one or more features



feature enable <feature-name-1> ... <feature-name-n>

        Enable one or more features



feature list [/Summary:true|false]

        Display list of available features



help <command>

        Display help text for <command>



help commands

        Display help text for all available commands



package create <extensionName> <path>

    Create a package for the extension <extensionName>

    (an extension being a module or a theme).

    The package will be output at the <path> specified.

    The default filename is Orchard.[Module|Theme].<extensionName>.<extensionVersion>.nupkg.

    For example, "package create SampleModule c:\temp" will create the package

    "c:\temp\Orchard.Module.SampleModule.1.0.0.nupkg".



package install <packageId> <location> /Version:<version>

        Install a module or a theme from a package file.



package uninstall <packageId>

    Uninstall a module or a theme.

    The <packageId> should take the format Orchard.[Module|Theme].<extensionName>.

    For example, "package uninstall Orchard.Module.SampleModule" will uninstall the Module under the "~/Modules/SampleModule" directory and

    "package uninstall Orchard.Theme.SampleTheme" will uninstall the Theme under the "~/Themes/SampleTheme" directory.



user create /UserName:<username> /Password:<password> /Email:<email>

        Creates a new User

The available commands depends on the features that are currently enabled for your site. To list the features that you can enable or disable, type "feature list" or "feature list /Summary:true". You can enable additional features (and thus, additional commands), by typing "feature enable <feature-name> at the command-prompt.

可用命令取决于您网站当前启用的功能。要列出可以启用或禁用的功能,请键入“功能列表”或“功能列表/摘要:true”。您可以通过在命令提示符下键入“feature enable&lt; feature-name&gt;”来启用其他功能(以及其他命令)。

orchard> feature list /Summary:true

Common, Enabled

Containers, Enabled

Contents, Enabled

Dashboard, Enabled

DatabaseUpdate, Disabled

Feeds, Enabled

Gallery, Enabled

HomePage, Enabled

Lucene, Disabled

Navigation, Enabled

Orchard.ArchiveLater, Disabled

Orchard.Blogs, Enabled

Orchard.Blogs.RemotePublishing, Disabled

Orchard.CodeGeneration, Enabled

Orchard.Comments, Enabled

Orchard.ContentTypes, Enabled

Orchard.Email, Disabled

Orchard.Experimental, Disabled

Orchard.Experimental.TestingLists, Disabled

Orchard.Experimental.WebCommandLine, Disabled

Orchard.Indexing, Disabled

Orchard.jQuery, Enabled

Orchard.Lists, Enabled

Orchard.Localization, Disabled

Orchard.Media, Enabled

Orchard.Messaging, Disabled

Orchard.Migrations, Disabled

Orchard.Modules, Enabled

Orchard.MultiTenancy, Disabled

Orchard.Packaging, Enabled

Orchard.Pages, Enabled

Orchard.PublishLater, Enabled

Orchard.Roles, Enabled

Orchard.Scripting, Enabled

Orchard.Scripting.Dlr, Disabled

Orchard.Scripting.Lightweight, Enabled

Orchard.Search, Disabled

Orchard.Setup, Disabled

Orchard.Tags, Enabled

Orchard.Themes, Enabled

Orchard.Users, Enabled

Orchard.Widgets, Enabled

PackagingServices, Enabled

Profiling, Disabled

Reports, Enabled

Routable, Enabled

SafeMode, Disabled

Scheduling, Enabled

Settings, Enabled

Shapes, Enabled

TheAdmin, Disabled

TheThemeMachine, Enabled

TinyMce, Enabled

XmlRpc, Disabled

Batched or scripted Commands

批处理或脚本命令

There are two specific "Non-interactive" modes; single command and response file. Each allow for useful batching of commands in a non-interactive context.

有两种特定的“非交互”模式;单个命令和响应文件。每个都允许在非交互式上下文中有用的命令批处理。

Commands still need to have been enabled, and orchard.exe still needs to be launched from the correct location for each command type.

仍然需要启用命令,并且仍需要从每个命令类型的正确位置启动orchard.exe。

Single Command

单一命令

Single command is exactly as you would expect. A single command can be run and the orchard.exe tool will exit directly after completion.

单个命令完全符合您的预期。可以运行单个命令,orchard.exe工具将在完成后直接退出。

From the Orchard.Web/bin path

从Orchard.Web / bin路径

orchard package create "Orchard.Blogs" "c:\\temp\\"

Response File

响应文件

A response file simply contains a series of lines, each one representing a command to be executed. This is an excellent way

响应文件只包含一系列行,每行代表一个要执行的命令。这是一个很好的方式

to run multiple commands without the large footprint of the orchard context initialisation.

在没有果园上下文初始化的大量足迹的情况下运行多个命令。

Example response file text (myfile.txt):

示例响应文件文本(myfile.txt):

package create "Orchard.Blogs" "c:\\temp\\"

package create "Orchard.Users" "c:\\temp\\"

To execute this response file run the orchard.exe in the single command mode as above, but note the "@" prefix on the parameter,

要执行此响应文件,请按上述单命令模式运行orchard.exe,但请注意参数上的“@”前缀,

indicating a response file

指示响应文件

orchard @myfile.txt

Adding Commands

添加命令

Modules developers can add their own commands to the system by implementing a new class deriving from Orchard.Commands.DefaultOrchardCommandHandler. A command is simply a method on that class that has the CommandName attribute. The following code creates a new "hello world" command that takes a name as a parameter and can take an optional "YouRock" switch.

模块开发人员可以通过实现从Orchard.Commands.DefaultOrchardCommandHandler派生的新类,将自己的命令添加到系统中。命令只是该类具有CommandName属性的方法。以下代码创建一个新的“hello world”命令,该命令将名称作为参数,并且可以使用可选的“YouRock”开关。

[CommandName("hello world")]

[CommandHelp(@"hello world <name> [/YouRock:true|false]

Says hello and whether you rock or not.")]

[OrchardSwitches("YouRock")]

public void HelloWorld(string name) {

    Context.Output.WriteLine(T("Hello {0}.", name ?? "world"));

    Context.Output.WriteLine(YouRock ? "You rock." : "You do not rock.");

}

The switch itself is declared as a property of the class:

交换机本身被声明为类的属性:

[OrchardSwitch]

public bool YouRock { get; set; }

Commands run in the full Orchard environment and can query the database, inject dependencies, and in general do almost anything that can be done from code running in the web site.

命令在完整的Orchard环境中运行,可以查询数据库,注入依赖项,并且通常可以完成从网站中运行的代码可以完成的任何操作。

Throwing Exceptions From Commands

从命令中抛出异常

Throwing from a command handler is not recommended. Instead, whenever possible, write to the context output and return. If you do want to throw a generic exception, you should throw an OrchardException.

不建议从命令处理程序中抛出。相反,只要有可能,写入上下文输出并返回。如果你想抛出一个通用异常,你应该抛出一个OrchardException。