Tags

, , , , , , , , , ,

This function was created to allow you to run a server compile from PowerShell.  I will apologize upfront to anyone on an earlier version of AX 2012 than R2 CU7.  This PowerShell function will only be useful if you are running a version of AX 2012 that is R2 CU7 or greater.  The reason being that R2 CU7 introduced the AxBuild.exe server compile.  There is a lot of information in the link regarding this process but for my purposes, the most important part was the difference in compile time.  Compilation time in my standalone development environment decreased from 4+ hours for the client compile to about 20 minutes when using the server compile.  I have other PowerShell functions that I will discuss in future posts that allow you use the client compile that is available in earlier versions but this one uses the server compile.

This function is also the main reason why I originally customized the Get-AXConfig function made available from the DynamicsAXCommunity PowerShell module that I discussed in an earlier post.  I needed the ServerBinDir for access to the AxBuild.exe server compile and the ServerLogDir for access to the compilation results file.  You will need to have the DynamicsAXCommunity PowerShell module installed and loaded in your session to use this function.  You should add the loading command for it to your profile.

  • Import-Module DynamicsAXCommunity -DisableNameChecking

The Start-AXBuildCompile function takes either 1 parameter or a mix of up to 8 parameters:

  • ConfigPath (Client configuration for the chosen AX environment)
  • AXVersion (This should be 6 but I’ve included it in anticipation for AX 7)
  • LogPath (Used to override the default location of the AXCompileAll.html file)
  • NoCleanup (Tells the program to keep the temporary files it writes under the %TEMP% directory)
  • StopAOS (In certain scenarios, the AxBuild.exe service might provide outdated metadata or outdated p-code to the compile process if the AOS is running)
  • SMTPServer (SMTP server to use to send the email)
  • MailMsg (Net.Mail.MailMessage object used to send the email)
  • VariablePath (Path to a file used to default the parameters/variables)
  • Workers (Used to force the number of workers used to compile from the default used by AXBuild.exe)

The VariablePath variable is being used in my functions to default variables.  It saves me time when running things in each environment to set up the variables beforehand and then I pass in the location of my D2D_PSFunctionVariables.ps1 file as this parameter.  This allows me to use these functions without filling out all of the variables in my PowerShell function calls.  You can find my D2D_PSFunctionVariables.ps1 file and the Start-AXBuildCompile custom PowerShell function in Codeplex.

The steps of this function aren’t overly complicated.  They are:

  • Load the variables if a VariablePath parameter is used
  • Get the AX environment info using Get-AXConfig
  • Stop the AOS if the switch parameters is passed
  • Build the command parameters for AXBuild.exe
  • Call the command using Invoke-Expression
  • Start the AOS if it was previously stopped
  • Get the file with the results of the compilation
  • Send an email with the compilation results file attached if a valid MailMessage variable is set up.  If one isn’t set up, you will need to navigate to the default location for this file on the AOS server to view it.

A couple of final things.  This function needs to be run on the AOS server.  It has not been built to allow remote functionality.  Also, I have only tested this function on AX 2012 R2 CU7 but I would expect it to work on R3 as well.  Please comment if there are any issues on R3.