CRM Blog

Tuesday, December 23, 2008 - Posts

Developing Portable Code For Microsoft CRM - Part II
by Danny Varghese 12.23.08

Comments    No Comments

 Intro

As mentioned in one of my earlier blog articles: http://www.crowehorwath.com/cs/blogs/crm/archive/2008/03/05/gac-it-developing-portable-code-for-microsoft-crm.aspx one can register assemblies in the GAC to help build a portable custom CRM solution.  In CRM 4.0, with the introduction of registering assemblies on the database server, developing portable code has gotten a bit easier. 

 

Building A Common Library

When developing plug-ins, often times developers find themselves either re-writing or re-using some common functionality.  For example connecting to a database, executing stored procedures, logging to a log file, even creating/updating entities.  When encountering these situations, I would recommend extracting out this logic and placing it in it's own assembly file acting as a library.  This then can be called by multiple assemblies/plug-ins thus reducing the amount of overall code, and maintenance.

 

Referencing The Common Library
When developing a plug-in, the best way to reference the library you've built is adding it as a project reference.  According to MSDN (http://msdn.microsoft.com/en-us/library/wkze6zky(VS.80).aspx) you should avoid adding file references to outputs of another project in the same solution, because doing so may cause compilation errors. Instead, use the Projects tab of the Add Reference dialog box to create project-to-project references. This makes team development easier, by allowing for better management of the class libraries you create in your projects.

 

Putting It All Together

Once you've developed your plug-in/custom assembly for CRM and the library, it's time to put it all together.  **NOTE**  Since plug-ins need to be strong typed, so do any files that it references.  So the library, if you're using it for plug-ins, will need to be strong typed.  First register the plug-in assembly file either on the database/server.  Then place the library in the <crm-root>\server\bin\assembly directory.  By doing this, anytime the plug-in executes, it will check this directory for the reference.  What this allows you to do is very easily develop a library to be used by all plug-ins and you don't have to use the GAC!  Happy coding!

Filed under: