Compilation Scope Overview
In Dynamics 365 Business Central there are different layers of controlling what can be published to the server and accessed from within a project.
Configuring extension target on the server
By setting the Allowed Extension Target Level flag in the server configuration, you control what can be published to the server by setting the Cloud or OnPrem flag. For more information, see Configuring Business Central Server.
Configuring extension target for an extension
In the manifest of an extension (the app.json file), you can set the target property to specify the compilation target of an extension. The available values are
Extension values have been deprecated starting with runtime 4.0 and replaced by the
target property informs the compiler which APIs can be used within the current project.
- If you specify
"target":"OnPrem"you can use any platform APIs and .NET types. This is the most permissive target. It is only if you specify this target that you can use methods marked with
Scope('OnPrem')or tables with the property Scope (Tables) set to
- If you specify
"target":"Cloud"you can only use APIs that are safe for use in a cloud environment. If the target is set to
Cloud, the extension cannot use any method marked with
Scope('OnPrem')or table with the property
OnPrem. Note: A table with the property
OnPremcarries this scope forward to every other object that might refer it as
SourceTable, even if those elements are declared within the same extension.
For example, if you have two extensions; A and B. Extension A has an app.json target setting
"target": "OnPrem"and defines a method with the Scope Attribute set to
[Scope('OnPrem')]. Extension B has a dependency on extension A and extension B has an app.json target setting
"target": "Cloud"and tries to call the method in extension A marked with scope
OnPrem, you will get a compile error when you are trying to compile extension B. For more information, see JSON Files.
Methods and tables scope
Methods can be marked with the
[Scope()] attribute to specify the compilation target and tables can be marked with the
Scope property. Both instruct the compiler which target the method or table can be used in. For more information, see Scope Attribute and Scope (Table) Property.