Best Practices tool
Best practices can be used to keep X++ code clean and uniform so that future developers can easily read the code to see what customizations have been done. Additionally, best practices can help keep code in line for future upgrades to alleviate issues. To enable a best practice check, you can go to Visual Studio > Extensions > Dynamics 365 > Options > Best Practices and view the best practices for each model. You can also turn off best practices for specific models on the Best Practices page.
The best practice check is run during the build. In the Results window, you can see all the best practice issues and the location of each issue. You can also run the best practice check from the command prompt. You can run best practices for all forms, specific elements, all items in a model, and items in all models and then write the output to a log file. The following list shows some code snippets for how to run best practices against different elements in the command prompt.
Run best practice on all forms in a module -
xppbp -module:FleetManagement form:*
Run best practice on specific elements -
xppbp -module:FleetManagement class:MyClass form:MyForm
Run best practice on all items in the model (and only for this one model in the module) -
xppbp -module:FleetManagement -model:FleetManagement -all
Run best practice on all items in all models in the module -
xppbp -module:FleetManagement -all
Write the best practice output to log files -
xppbp -module:FleetManagement -all -xmllog=Log.xml -log=Log.txt
You can suppress best practice checks for each model. To do this, you
can right-click your project and select Edit best practice
suppressions. This will open an XML file where you can suppress best
practices. You will need to add the model that you want to suppress by using the tags DiagnosticType
, Severity
, Path
, Moniker
, and Justification
. You should be able to copy the information
from the model's BuildModelResult.xml that is created during the build
into the Edit Best Practice Suppressions XML file. The justification
message might need to be modified to be more meaningful.
<Diagnostic>
<DiagnosticType>BestPractices</DiagnosticType>
<Severity>Warning</Severity>
<Path>AxForm/AssetWarehouseTransfer/Design</Path>
<Moniker>BPErrorFormDesignPatternUnspecified</Moniker>
<Justification>Microsoft surely assigns a pattern soon.</Justification>
</Diagnostic>