We all know about XrmToolBox – it’s a tool of choice for a lot of Dynamics consultants. Although, it is, really, a set of tools rather than just a single one.. But, either way, you’ve likely heard about it.
Worst case scenario – you just learned about it from this post.. in which case I would actually insist that you download the tool right now (hint: it’s free) from the XrmToolBox web site:
So, let’s assume you have XrmToolBox, and let’s say you know how to use it. How about using it for the strange purpose of running C# code into Dynamics? After all, XrmToolBox is, already, connected to your Dynamics organization, so all you are missing is an XrmToolBox plugin that will allow you to run the code.
To tell you the truth, I just wanted to see how it works out.. It did work – see below:
1. Download XrmToolBox plugin from this url:
http://www.itaintboring.com/downloads/TreeCat.XrmToolBox.CodeNow.zip
2. Deploy that plugin to the XrmToolBox folder
– Unpackage that zip file
– Put the dll you’ll find there into the XrmToolBox plugins folder (which is: %AppData%\MscrmTools\XrmToolBox\Plugins )
3. Restart (or open) XrmToolBox – you’ll see another plugin there
(Yes, I know.. I should have added some nice logo)
4. Don’t open it yet – first, connect to your Dynamics organization
5. Then open the plugin
6. You can, actually, hit “Run Code” – the code will run and it will print account names for all accounts in your Dynamics organization
What if you wanted to change the code?
First of all, feel free to do it! What you have there by default is just an example to get you started.
However, keep in mind a few things:
- You have to have a public static void CodeNow() method in your code
- You can use Service property (IOrganizationService) and LogMessage method in your code (sure you can use others.. but that Service will already be connected to Dynamics, and LogMessage will print a message in the log area of the plugin)
- Do not define classes or namespaces in this version, just use static methods. Actually, you can probably define a class.. I did not try but it should work
- In the “Using” area, add all the namespaces just like you would do it in your regular C# file
- Here is the list of referenced assemblies your code can use: System.Drawing.dll, Microsoft.IdentityModel.dll, System.ServiceModel.dllSystem.Runtime.Serialization.dll, Microsoft.Xrm.Sdk.dll, Microsoft.Xrm.Tooling.Connector.dll,Microsoft.Crm.Sdk.Proxy.dll
Have fun!
Continue reading about CodeNow plugin: Syntax Highlighting
PS. Since CodeNow plugin has a home page now, don’t be a stranger – stop by any time: http://www.itaintboring.com/tcs-tools/code-now-plugin-for-xrmtoolbox/
Very practical for non-fulltime devs. Can you also bring it to the XrmToolBox plugin store for a more convenient installation?
Pingback: Code Now: run the code, build a plugin, or create a utility.. directly in #XrmToolBox - Microsoft Dynamics CRM Community
This looks great.. but every time i try to compile i’m getting errors about missing DLL’s:
Error (CS0006): Metadata file ‘Microsoft.IdentityModel.dll’ could not be found
Error (CS0006): Metadata file ‘Microsoft.Crm.Sdk.Proxy.dll’ could not be found
Error (CS0006): Metadata file ‘Microsoft.Xrm.Sdk.dll’ could not be found
Error (CS0006): Metadata file ‘Microsoft.Xrm.Tooling.Connector.dll’ could not be found
What folder is this expecting the DLL’s to be in?
Hi JD,
are you compiling a dll or an exe? In either case, you are not supposed to put those dlls in any specific folder – they are all there in the XrmToolBox folder.
If it’s still not working, please drop me some screenshots at [email protected]
Hey guys,
just wondering, did you manage to solve this issue? I’ve got the same when compiling.
Regards,
Jeroen
Turned out this was a problem with how you were starting XrmToolBox. Basically, it has to be started with the correct “current directory” (so starting it from a batch file or using a shortcut with different current directory might confuse the plugin and it won’t be able to find the dll-s which are normally located in the XrmlToolBox folder)
That worked for me
Thanks