Code Now: run the code, build a plugin, or create a utility.. directly in #XrmToolBox

By | August 4, 2017

Just fresh from development, a few more tools have been added to the Code Now plugin for XrmToolBox:

  • Code Now can build an exe-file
  • Code Now can build a plugin
  • You can save your code to a file and/or load it from a file

And, because it’s CodeNow, you can do it right NOW, without even having to deploy a Visual Studio.

If you are wondering what that plugin is, you may want to read this post first:

Run C# code into Dynamics NOW!

Eventually, you should be able to download the plugin directly from the plugin store, but, for the time being, you need to download it from this site (make sure to read the post above – all those details are there)

So, how does it work with the executables/plugins?

It’s all done using the compile command. Whether the plugin will build an exe-file or a dll (for a plugin) depends on whether you have selected that “Plugin” checkbox:

Creating an exe-file

When building an exe file, the tool will take your CodeNow function and “using” directives, it will add some extra code required for the executable to compile, and it will build an “exe” file after that.

You will need to:

  • Name the file when the tool asks you for it
  • And click OK

Once the file is ready, and that should take just a few seconds, you’ll see that file and a few additional dll files in the folder:

In the example above, I just created that “getaccounts.exe” file.

What you still need to do after that manually(for now), you need to open getaccounts.exe.config file (if you name the file differently, this configuration file will also be named differently), and you need to configure the connection string.

Here is how it will look like when you open it:

What you see on the screenshot are a few sample connection strings which you can use to define your own connection. Just make sure to keep the same connection name (CodeNow).

If you wanted to see more examples, the msdn page below would definitely help:

Have a look at the screenshot below – I just added the connection string for my online Dynamics 365 trial instance:

And, of course, once you have configured the connection, save the file.

What you just did with the connection string only needs to be done once. Next time you compile that exe file, the configuration file will not be replaced, so, if it’s the second time you are compiling the file.. you could have skipped all those configuration steps and start your utility right away.

Remember there was that “LogMessage” method available to you when you were using “Run Code” option? Once you have an exe, LogMessage will still work, but it will be redirecting all output to the console. Here is what you are going to see then:

And that’s it. If you want, you can keep running your new utility manually. Or you can choose to schedule it.. Maybe there is something you need to do in Dynamics every morning at 6AM? Not a problem – build a utility, schedule it with Windows Task Scheduler, and don’t bother wakeing up that early anymore.

But, there is another option, too – you can also build a Dynamics plugin using CodeNow. I will explain how that works in a separate post, but, if you want, you can try it right NOW:) Or wait until tomorrow..

Build a plugin for Dynamics using CodeNow

2 thoughts on “Code Now: run the code, build a plugin, or create a utility.. directly in #XrmToolBox

  1. Kevin

    Hey. Trying to use this instead of writing a console app. Seems like an easier way to go.
    My code looks like below….
    When I run the compiled .exe file I get an error.
    Error: Unhandled Exception: System. NullReferenceException: Object reference not set to an instance of an object.
    at ToolBoxSnippet.Program.Main()

    public static void CodeNow(){

    string fetchXml = @”


    var results = Service.RetrieveMultiple(new FetchExpression(fetchXml)).Entities;
    foreach(var r in results)


    Nothing obvious comes at me as an error. Can you help out?


Leave a Reply

Your email address will not be published. Required fields are marked *