I wanted to share an issue you may face when exporting models using the AX 2012 powershell cmdlets. As per the system requirements, we recommend using Powershell v2.0. However you may have Powershell v3 and above installed on your system (like Windows Server 2012 R2), and this can cause the following issues:
Unable to import models using AXUTIL.EXE, where the models were created using Powershell cmdlet Export-AxModel.
To demonstrate the issue create a custom model file, in this example we refer to a model called “Demo Model”
Example, run the AX Management Shell and then run the following command to export a custom model called ‘Demo model’
Export-AXModel -model “DEMO MODEL” -file c:\temp\demo1.axmodel
Run an elevated cmd prompt and import demo1.axmodel using axutil.exe:
axutil import /file:c:\temp\demo1.axmodel
We get an error:
ERROR: Could not load file or assembly ‘C:\TEMP\demo1.axmodel’ or one of its dependencies. This assembly is
built by a runtime newer than the currently loaded runtime and cannot be loaded.
(However importing the same model using Install-AXModel cmdlet works fine).
Or if you import the model in to your LCS Project (https://lcs.dynamics.com) under the “Customization analysis” tool, you will get an error as follows:
Only models exported with AxUtil version 184.108.40.2061 or lower can be uploaded to this project
Also notice that the same model exported by powershell cmdlet is a different file size, compared to it being exported by axutil.exe
e.g. Export the ‘Demo Model’ using axutil.exe
axutil export /model:”DEMO MODEL” /file:c:\temp\demo2.axmodel
Now compare file sizes of demo1.axmodel and demo2.axmodel, and notice that demo1.axmodel file is
Powershell v3 and above uses a different Microsoft .NET Framework build then v2.
This issue can be resolved by enforcing the AX Management Shell to use Powershell Version 2 framework instead as follows:
Secondary mouse-click on the “Microsoft Dynamics AX Management Shell” icon in “Administrative tools” and select properties.
By default it will have the following target cmdline (or something similar):
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned -NoExit & ‘C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities\Microsoft.Dynamics.ManagementUtilities.ps1’
Change the target cmd line on your system by adding one more argument: -Version 2 as follows:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Version 2 –ExecutionPolicy RemoteSigned -NoExit & ‘C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities\Microsoft.Dynamics.ManagementUtilities.ps1’
Now you should be able to create the correct model file format when running the Export-AXModel cmdlet in the “Microsoft Dynamics AX Management Shell”.