# 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

- You have already setup Sitecore site visual studio solution.
    - If not then you may follow the steps mentioned here on John West's Blog or Check out Sitecore training series on YouTube - [Sitecore Training : Developer Fundamental Series - Creating Visual Studio Project For Sitecore](http://www.youtube.com/watch?v=UHyDQ1lx9S0).
- Installed and Configured Sitecore Rocks with Visual Studio solution for Sitecore site.
    - If not then check the Sitecore training series on YouTube -
        - [Sitecore Rocks Training: Installation Series - Sitecore Rocks Visual Studio Plug-in Installation](http://www.youtube.com/watch?v=o0vh51tzVCM)
        - [Sitecore Rocks Training : Installation Series - Creating a Sitecore Rocks Connection](http://www.youtube.com/watch?v=Vu0dtMRfAv8)
        - [Sitecore Rocks Training : Installation Series - Installing Sitecore Rocks from VSIX](http://www.youtube.com/watch?v=BbTguDprxCE)
        - [Sitecore Rocks Training : Installation Series - Sitecore Rocks Windows Desktop Installer](http://www.youtube.com/watch?v=z0LOXyamkjk)

## 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](images/sitecore-codegen-create-strongly-typed-items-file-300x158.png)](http://www.harshbaid.in/wp-content/uploads/2013/09/sitecore-codegen-create-strongly-typed-items-file.png) Create new file for Code generation  
Right click on project > Add > New Item > Visual C# > Sitecore > Code Generation > select Strongly Typed Items > click Add

<figure>

![sitecore codegen - run custom tool](images/sitecore-codegen-run-custom-tool-300x248.png)

<figcaption>Run custom tool command to execute and generate code files</figcaption>

</figure>

<figure>

![sitecore codegen - code generated in designer file](images/sitecore-codegen-code-generated-in-designer-file-300x161.png)

<figcaption>Verify the Code generated in CodeGenerationFile.Designer.cs file (File name may differ as per added file)</figcaption>

</figure>

## 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

- Sitecore Training YouTube channel
- [Question on Stackoverflow for how to use Sitecore Rocks for Code Generation](http://stackoverflow.com/q/6962920/468718 "How to invoke 'Sitecore Rocks' code generation?")
- Blog post - Sitecore Rocks Visual Studio Add Item Templates
- Blog post - Creating Sitecore Visual Studio Solution

_Do comment if you like this post or have any opinions._

## Related articles

- [Fixing up Sitecore.Nuget connections](http://kevinobee.wordpress.com/2013/08/04/fixing-up-sitecore-nuget-connections/)
- [Glimpse for Sitecore](http://kevinobee.wordpress.com/2013/08/25/glimpse-for-sitecore/)


