Monday 13 February 2012

Orchard CMS command line tips


When working in Orchard CMS you'll probably come across the Command Line sooner or later. This shell allows you to automate certain tasks for Orchard or execute commands not available in the admin UI.

Here are a few tips to make life easier when working with the command line.

Prepare
When you are running from the downloaded source code you need to prep a bit to make it easier.
If you are running an Orchard from WebMatrix, it is sufficient to navigate to the bin folder and start Orchard.exe in the command line from there.


You want to prepare yourself first to save a lot of typing and directory swapping stuff. We'll use the good old Windows environment variables PATH.


1. In Windows 7; go to Control Panel > System and Security > System and click "Advanced system settings" on the left menu.
2. Open the "Environment Variables" (button at the bottom).
3. On the lower section "System Variables" scroll to the "Path" variables and add the folder where the Orchard.exe file exists. 

Update: tbh, I made a mistake here, so let me correct this. In order to start the Orchard.exe command line it's actually simpler:

  • For source code downloads: navigate to the Orchard.Web project folder and type in a command window: "bin\orchard" this will position you on the correct directory (of the web project) to perform command actions
  • For the WebMatrix orchard site, just navigate to the site directory and  type in a command window: "bin\orchard" which will position you also on the correct location.
Open the command line
When you start the Orchard Command line, best is that you start it from the location of your website.

So, if your website is located for example at: C:\Users\JohnDoe\Documents\My Web Sites\MyOrchardWebsite, then start a command line from there. The easiest way to do this in Windows 7 is to shift-right click the folder and select "Open command window here".

Now you can type the command Orchard and you'll see your command prompt ready for use

Orchard>

Who wins?
When the website is running locally you won't be able to start the Orchard command line. So you need to stop it first.
  • If you started from WebMatrix, then you go to your system tray and find IIS Express to shut down the running Orchard site.
  • If you were running from Visual Studio then you just have to stop debugging your website to get it going.
Note that you can also work with IIS Express from Visual Studio instead of the original Casini Web Development Server. In that case you ofc stop IIS Express.