Using the extension

Using the extension

To use the extension, once a project has been loaded, simply right-click on a file within the Visual Studio Solution Explorer, and the extension will appear on the menu at the bottom.

Configuration

To be able to do anything, you must first set up which CRM server to connect to.  These settings are saved at the project level, not the solution level, so if you have a solution with multiple projects, you will get a separate configuration file per project.

To configure your connection, simply select Configuration from the pop up menu.

Enter the Url to the CRM server you wish to connect to, your username and password, and click the Test Connection button to connect.

It will inform you that it is attempting to connect.

If successful, it will inform you that the settings have been saved. Simply close the configuration dialog.

Multiple connections

It is now also possible to have multiple connections for each Project within Visual Studio.  The Configuration tab allows you to create a new connection set.

Simply click the Plus or Minus buttons to create a new Connection Set.  At the moment, you cannot rename a connection.  When linking files, you are given a selector at the top of the window allowing you to choose which connection to link the file to.  One file can only be linked to one Connection.

 

Web Resource Linker

To publish Web Resources to the CRM Server, each individual Web Resource in your Visual Studio Project must be first Linked to the appropriate Resource within CRM.  To do this, right-click on a file in the Solution Explorer and simply choose Link Web Resource from the menu. You can also select Multiple files with the CTRL and SHIFT keys.

This will show you the Linker Dialog after a few moments.

Simply select which Web Resource the selected file matches and click the Link button.  After saving a Link between the Visual Studio file and the CRM Web Resource, it will also Publish the Web Resource to the CRM System.

Any status messages can be viewed in the Visual Studio Output window under the Dynamics CRM Utilities section.

Once a file or files have been linked, in future, after making changes to them in Visual Studio, you simply need to select Publish from the Pop Up Menu, and the file will be published to CRM.

Shortcut Key

You may wish to assign a Shortcut Key within Visual Studio.  This enables you to Publish as soon as you have finished editing a Web Resource with a press of a Key.

In Visual Studio, go to the Tools Menu, and choose Options.

On the screen that pops up, select Keyboard in the list, and type “crmutilities” in the text box as shown below.

Select the PublishWebResource option and click in the Press shortcut keys text box. Choose an appropriate set of keys you are comfortable with (CTRL+SHIFT+P is a good combination).  It will inform you of if the set of keys is already in use (in the example above, they are bound to a feature that is unlikely to be used) and hit OK.

From now on, if you have either a file selected in the Solution Explorer, or a file open on-screen, pressing you’re chosen Keys will initiate the Publish of the Web Resource.  If the file is not already mapped to a web resource, the linker dialog will appear allowing you to choose the location to publish to.

Fetch XML

The Fetch XML option in the Dynamics CRM Utilities Extension allows you to run Fetch XML Queries against the CRM Server.  These Queries can be saved in XML files and stored within the Visual Studio Project if required.

Simply create a new XML file or select an existing file within the Visual Studio Project, right-click and choose Execute FetchXML from the menu.

This will display the FetchXML tool window, and if the file that was clicked on contained valid XML, it will be executed and the results shown.

At any point, click the Tab titled Source to view or change the FetchXML.  Note that this does not change the file within Visual Studio.  It is expected that you modify the file within Visual Studios own Editor before running it within the Tool.

You can also specify a comma separated list of columns in the Columns box to reorder and rename the column headers.

For example,

This Column definition can also be stored within Visual Studio if you wish.  In the Visual Studio Solution Explorer, simply right-click the FetchXML file and choose Create FetchXML Layout.  This will create an additional file attached to the original FetchXML file where you can define the column layout.

You can also use Parameter Replacement in you FetchXML conditions by placing a token somewhere in the file with square brackets, for example:

[keyword]

This will then show up in the Parameters list.

Double clicking the Parameter will allow you to enter a value before executing the FetchXML.

At any point, you can also export the results of a Query to a CSV file by clicking on the Save To CSV button.

Generate Classes for Entities

Most CRM Developers either use, or have at least heard of CrmSvcUtil for generating early bound classes for developing code and using the resulting classes to manipulate CRM data.  I personally do not like working with early bound entities as the resulting class files are huge, and I personally prefer working with the standard Entity Framework for creating and updating entities, and for Linq queries.

Often, I use some helper class libraries that I can use to represent the custom entity names and attributes, so that they can be referenced in code and provide a degree of separation from the actual Schema names and to make code easier to write, and support Intelli-sense.

Something like the code sample below:


public static class Contact
{
    public static const string EntityName = "contact";
    public static const string Name = "fullname";
}

This would then allow you to do the following:

public void createContact()
{
    Entity contact = new Entity(Contact.EntityName);
    contact[Contact.Name] = "Joe Blogs";
    service.Create(contact);
}

The Utilities offers the ability to generate these kind of class files automatically for you.

To use it, simply right click on a folder within your Visual Studio project (it has to be either a folder, or an existing class), and choose one of the options to generate the helper class for either Custom Entities or Standard Entities.

This will generate a class file called either CustomEntities,cs or StandardEntities.cs. The Dynamics class can then be used in your code to reference the attributes and option sets for your CRM system.

If you right click a folder that already contains these class files, new files are created with a unique number attached as well so you can keep different version numbers if required.

If you right click a class file and choose an option then the contents of that file will be overwritten with the new classes.

You can also specify the Namespace and the Class Name that the files are auto generated with if required.  To do this, simply choose the Generate Class Options menu.