Categories
.NET ASP.NET Sitecore Utility

Code Generation using Sitecore Rocks and Visual Studio

Index Points

  1. Introduction
  2. Assumptions
  3. Code Generation Steps using Sitecore Rocks
  4. Image Guided Steps for Code Generation using Sitecore Rocks
  5. Conclusion
  6. Reference Links

 

Introduction

This post will guide you on how to work with code generation using Sitecore Rocks.

Assumptions

Code Generation Steps using Sitecore Rocks

For Code generation using Sitecore Rocks the steps are:

  1. Setup the Sitecore site using .exe installer or Siteroot zip – available from Sitecore SDN.
  2. Setup Sitecore site in Visual studio solution – Creating .sln file.
  3. Install Sitecore Rocks (if not already installed).
  4. Connect the Visual studio solution with Sitecore site using Hard Rock web service exposed by Sitecore.
  5. Create new StronglyTypedItems file in Sitecore visual studio solution, extension will be .scx, with appropriate name – for example “CodeGenerationFile.scx”.
  6. Right-click on created file “CodeGenerationFile.scx” and execute the command ‘Run Custom Tool’ for code generation.

Note: Check YouTube video series linked in assumption section for information on how to install and setup Sitecore Rocks and Sitecore Visual studio solution.

Image Guided Steps for Code Generation using Sitecore Rocks

The visual steps for Sitecore Rocks code generation are as below:

sitecore codegen - create strongly typed items file
Create new file for Code generation
Right click on project > Add > New Item > Visual C# > Sitecore > Code Generation > select Strongly Typed Items > click Add
sitecore codegen - run custom tool
Run custom tool command to execute and generate code files
sitecore codegen - code generated in designer file
Verify the Code generated in CodeGenerationFile.Designer.cs file (File name may differ as per added file)

Conclusion

Code generation with Sitecore Rocks is very easy to follow. After generating code using Sitecore Rocks, developers may move the classes to relatively named class files by themselves or using command ‘Move class to file’ using ReSharper tool.

Reference Links

Do comment if you like this post or have any opinions.

4 replies on “Code Generation using Sitecore Rocks and Visual Studio”

We have generated classes based on templates using guidelines provided above. We are not able to render image on .aspx page. Please help us regarding the same.

As of today, I would advice to use glass mapper since it also provides rendering controls along with ORM features. When using Sitecore Rocks’ code generation you have to use the Sitecore provided controls for rendering images such as <sc:image /> control to keep supporting Experience Editor (previously Page Editor).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site supports SyntaxHighlighter via WP SyntaxHighlighter. It can highlight your code.
How to highlight your code: Paste your code in the comment form, select it and then click the language link button below. This will wrap your code in a <pre> tag(or shortcode) and format it when submitted.

This site uses Akismet to reduce spam. Learn how your comment data is processed.