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))] public class 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:
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)
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:
“Copying “C:\Users\Administrator\Documents\Visual Studio 2015\Projects\MySolution1\MyProject1\bin\Debug\MyAddIn.dll” to Dynamics Addins folder C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\0ueyjx1c.4xo\AddinExtensions.”
1 File(s) copied
2 File(s) copied
========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========