Dynamics AX7 Add-ins : Deploying separate assemblies

A small tip today for those creating add-ins for Dynamics AX7. If you are creating an add-in, the template provides you with a project containing a class for your menu add-in.

[Export(typeof(IMainMenu))]publicclass MainMenuAddIn : MainMenuBase

The other thing present in your project is a post-build script that will copy the target assembly to the extension folder of the Dynamics AX 7 Visual Studio extension. By doing so, your add-in will be picked up and loaded by the Dynamics AX 7 extension.

While creating some extensions, I often use separate projects that result in class libraries that contain logic. But if you do this, by default, your add-in will throw exceptions that the referenced assembly could not be loaded. This is because your assembly also needs to be in the folder containing the Dynamics AX 7 extension.

To solve this, you can change the post-build script to also copy other required assemblies.
Look for the line containing:

SET InstallingAssembly=%1

And add the following line below. (Note that the sample filter MyProject*.dll needs to be replaced with a filter that matches your assemblies that you want to copy)

SET InstallingMyAssembliesFilter=%2MyProject*.dll

A bit further, add the following line behind the xcopy line

call xcopy /q /y %InstallingMyAssembliesFilter% .

That should do it for the script itself. The last thing to do is call it post build.
So in the project properties, add the following in the post-build event command line:

call "$(ProjectDir)\installtovs.bat" "$(TargetPath)" "$(TargetDir)"

Now when you build you solution, you should see the following in your output window: