Global Office Directory
More Products
Share this page
Home > Community > Technical Blogs > John West Sitecore Blog > Sitecore Rocks Extensions
This blog post contains information about extensions for Sitecore Rocks, the Visual Studio extension for developers working with the ASP.NET CMS. For more information about Sitecore Rocks, see my blog post Introducing Sitecore Rocks. For more information about extending Sitecore Rocks, see my blog post Sitecore Rocks Plugins and Extensions.
Extensions are light-weight plugins compiled automatically in the background. Extensions provide the easiest mechanism for extending Sitecore Rocks. To implement an extension, you don't even need to create a Visual Studio project - you just write some code, and Rocks applies it automatically. You can later convert an extension to a project.
Before you can create an extension, you need to enable extensions. To enable extensions:
Creating an extension is incredibly easy. To create an extension:
Sitecore creates a code file for the extension. That's it; if you right-click the same object again, your extension appears towards the top of the menu. If Sitecore Rocks cannot compile the code, it writes errors to a file named after the project in a directory named after the project under the AppData\Local\Sitecore\Sitecore.Rocks\Extensions folder for the user.
The default code for a new extension class provides a stub that simply pops up an alert with the name you entered for the extension. The constructor defines three key properties of the extension. The class inherits from the Sitecore.VisualStudio.Commands class and is decorated with the [Command] attribute. The default constructor sets three key properties:
The default code also implements the CanExecute() method that controls on which menus the extension appears. Basically, each time it needs to generate a context menu, Sitecore Rocks passes a context argument to this method in each command class, and includes only those commands for which this method returns true. This method typically checks the type of the parameter, the number of items selected in the user interface and/or the type of selected item(s) to see if the command is relevant to the calling context.
The Execute() method contains the body of the implementation. Sitecore Rocks passes the same parameter to this method that it passed to the CanExecute() method. For example code, see existing plugins in the repository (in Visual Studio, click the Sitecore menu, and then click Plugins...).
To convert an extension to a Visual Studio project:
For more information about working with Sitecore Rocks Visual Studio projects, see http://vsplugins.sitecore.net/Creating-Visual-Studio-Projects.ashx.
Tags: API, Architecture, Infrastructure, Integration
John has over ten years of experience in the CMS industry. His areas of focus include the Sitecore community, Web industry research, Sitecore technical documentation, and product management.
This website is designed to be fully functional with scripts disabled in browser. Please contact the webmaster for any suggestions