Prepare your Microsoft Dynamics 365 Business Central Extension for AppSource
If you are developing an extension for Dynamics 365 Business Central, your codebase will be required to follow the guidelines set by Microsoft to publish it on Microsoft AppSource. One of the checklist items [1] is to pass your codebase through built-in code analyzers that build on the compiler’s functionality to offer developers analysis of the syntax and semantics at build time. As of writing this article, The AL Language extension for Visual Studio Code contains four analyzers:
- CodeCop is an analyzer that enforces the official AL Coding Guidelines.
- PerTenantExtensionCop is an analyzer that enforces rules that must be respected by extensions meant to be installed for individual tenants.
- AppSourceCop is an analyzer that enforces rules that must be respected by extensions meant to be published to Microsoft AppSource.
- UICop is an analyzer that enforces rules that must be respected by extensions meant to customize a user interface.
Steps to Enable Code Analyzers in VSCode
Open VSCode and your Project, then follow the following steps;
- Click on ‘File’
- Click on ‘Preferences’
- Click on ‘Settings’
- A Settings tab will open
- Click on ‘Workspace’
- Type enablecodeanalysis in the Search
- Tick ‘Enable Code Analysis’
You will at this point have a file settings.json in your .vscode folder where your launch.json file is normally found. Open the settings.json file to find the following code;
To enable the code analyzers, add a property al.codeAnalyzers to the JSON object followed by the analyzer(s) you want to enable. In this example, we will enable the CodeCop and AppSourceCop;
At this point, analyzers will run through your codebase and point issues it found with your code, it will show you green/yellow/red lines beneath your code, and you can see the exact “problem” as a tooltip when you hover over it, or in the “problems” — pane. Fixing the suggested issues will prepare your codebase against the selected rules.
NOTE: If you add PerTenantExtensionCop analyzer and are missing Permissions.xml file, you’re going to get a compile error: “Table ‘XXXXX’ is missing a matching permission set”. To generate the Permissions.xml file, update to the latest version of AL Language and run the command; “Generate permission set containing current extension objects” in VSCode’s Command Pallete. This will help ensure that all relevant permission sets are created in XML format and you will have Permissions.xml file in your project.