AX 2012 – “Lights out” System Compile

As most of you are aware by now, AX 2012 makes extensive use of .NET CIL to perform various functions within the system e.g. the AIF framework, AX Batch Server, AX SSRS Reports, etc – all of these components now run as .NET CIL instead of X++ code.
This has made it increasingly important to regularly compile your X++ code into CIL using either of the following methods:
  • Full CIL Generation
  • Incremental CIL generation.
To ensure a healthy system during development, I would recommend that you regularly perform a full system compile. The problem is that this can be a time consuming task, as it requires a two-stepped process that needs to be manually kicked off one after the other i.e. A System Administrator triggers the Full System Compile Step, and then once that successfully completed, (s)he can then trigger the Full CIL compilation.
This can end up being an extremely painful process, as it normally requires this task to be performed outside of working hours, and for somebody to stay up late to wait for the Full System Compile to finish so that the CIL compile can be started.
To get around this, we can make use of a batch script that will perform both of these tasks outside of working hours, which can then be scheduled to run nightly.
This blog will provide a basic example of the AX32.exe commands that can be used to perform the required system compilations (FYI – There are several blogs on the internet that talks about creating automated build scripts. These blogs go into a lot more detail about deploying models, loading XPO files, etc. So if you need to perform these tasks, please don’t hesitate to go and check them out).
For my “Lights out” compilation script, I’m going to perform the following very basic tasks:
The following screenshot shows a batch script that performs all of the tasks as summarized above (Each section within the script will be described in more detail later in this blog):

Script Variables

SET serviceName=AOS60$01

SET aosHost=AX2012-A

SET aosPort=2712

SET appPath=”C:\Program Files (X86)\Microsoft Dynamics AX\60\Client\Bin\AX32.EXE”

The first section of the script should be pretty self-explanatory i.e. 4 variables that are used to identify the name of the AOS Service (as shown in the Services Management snap-in), the server hosting the AOS Server, the Port number assigned to the AOS Server, and then finally the Path to the AX Client executable.
(I’ve included the Host Name and Port number parameters to allow for environments where multiple AOS servers are installed on a single host e.g. a DEV and TEST environments).
Restart AOS Server

net stop %serviceName%

net start %serviceName%

The next section in the script restarts the AOS server. I include this restart step to ensure that the latest label file changes are loaded into the AX Model Store.
Perform Full System Compile

%appPath% -aos2=%aosHost%:%aosPort% -startupcmd=CompileAll_- -lazytableloading -lazyclassloading

Once the AOS service has been restarted, I initiate the Full X++ compile command.
The AX32 executable supports multiple command line parameters (A full listing can be found here). The two significant parameters are: -aos2 AND –startupcmd.
  • The –aos2 command line parameter is used to tell the AX32 executable which AOS Server to connect to.
  • The –startupCmd command line parameter tells the AX32 executable which command to execute during start-up.
    You will notice that I’ve included a _- at the end of the CompileAll command. This tells AX to perform a full system compile, but NOT update the Cross Reference information. If you want to perform a Cross Reference update, change the value to _+.
The other two parameters used in this script are: -lazytableloading AND –lazyclassloading.
When the AX client starts up, it performs various initialization tasks to improve the overall performance of the client e.g. the system pre-compiles and loads various system tables and classes into memory for quick reference.
This process slows down the initial start-up time of the AX client.
For the purpose of doing a full system compile, these performance optimization tasks performed during start-up doesn’t provide any benefit to us, so by using the –lazytableloading and –lazyclassloading parameters we tell the application to not perform these tasks during start-up.
Perform Full CIL Compile

%appPath% -aos2=%aosHost%:%aosPort% -startupcmd=CompileIl -lazytableloading -lazyclassloading
After the full compile is completed we use the same AX32 command, but this time we use the CompileIL start-up command.
Restart AOS Server

net stop %serviceName%

net start %serviceName%

And finally we restart the AOS service to release all of the system resources that used during the compilation process.

Now there are several enhancements that can be made to this script e.g. checking to see if any errors occurred during the Full X++ compile, and then only initiating the CIL compile if no errors occurred. But this is something for another day.
I hope this proves useful, and let me know if you have any questions.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.