Add a template to your project

  1. Highlight the project where you want to store the template and generated code.   
  2. Tools –> Add CRM Code Generator Template...  (if you don’t see this menu, then shutdwon visual studio and reinstall the extension)
    image_thumb2

Start with one of the provided templates

  • CrmSvcUtil.tt – Code generated from this will be exactly what is produced from CRmSvcUtil.exe
  • CrmSvcUtilExtended.tt – Adds fieldname & Option Sets values  (used v2 instead)
  • CrmSvcUtilExtendedV2.tt – Adds enum properties for all Two Option and Option Set fields (this is the one I use)
  • JavaScript.tt – Example of how to generate a JavaScript file from the CRM Schema (from https://crm2011codegen.codeplex.com )
  • CSharp.tt – POCO example of how to put C# data annotation on the fields.  (requires you to put a reference to  System.ComponentModel.DataAnnotations in your project)
  • Sample.tt – Just another example of how to create a template for C#

Connection & Entities

  1. After a template is added to your project you will be prompted for CRM connection info.  Connection info is saved to the .SLN file (username & password are saved to .SUO).
  2. Pick the entities that you want to include. (NOTE: if you click refresh you must have all the connection information filled out)
  3. Click the “Generate Code” button (this process takes about 45 seconds, but seems like 5 minutes)
  4. When the dialog goes away, it’s done and the generated code is ready to use.

Refreshing metadata from the server

If you make schema changes in CRM and you want to refresh the code,   right click the template and select “Run Custom Tool

image_thumb3

Changing the template

When you make changes to the template and save, Visual Studio will automatically attempt to re-generate the code.   HINT: select ‘No’ for fresh entities if you have just made changes in the template and don’t need to refresh from the CRM server, it will be much faster

Last edited Apr 2, 2016 at 2:40 PM by airrick2, version 4