[Scope('OnPrem')] don't works
Hi, my project is target on "cloud", but when I right the "[Scope('OnPrem')]" before my procedure VSC tells me there's a problem : The type or method 'ServerDirectoryExists' cannot be used for 'Cloud' development. AL(AL0296)
take a look at one of the examples of my project on this picture :

I specify that we want to work both in the cloud and Onprem but without making two different code bases.
Al language : 5.0.288712
How can it possibly work for cloud deployment when that function is not available/usable in the cloud...?
I have one code base for 2 deployments : Cloud and OnPrem. And i just want to use this function in "OnPrem" not in Cloud" without making 2 different code bases.
So you want some build-time way to act like OnPrem functions aren't there, when building for Cloud? Sounds like a pre-processor #ifdef from the old days.
That's exactly right.
What is the use of [Scope('OnPrem')] if it's not ignored in cloud ?
[Scope('OnPrem')] is used to specify that the procedure can only be used by extensions which have their manifest (app.json) target set to OnPrem.
See:
- https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-json-files#Appjson
- https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods/devenv-scope-attribute
The compiler seems to be behaving as expected here
Yeah I know that but why is there a problem here when I write "[Scope('OnPrem')]" before the function? Why the compiler don't ignore this function when I'm in cloud?
Probably because that opens up a lot more questions. Just ignoring the function seems easy enough. But what if it's called somewhere else? Then the compiler can't just assume it can get rid of the call because its result might be used or it might have side-effects or whatever. So you then end up wanting a more general way to mark certain areas of code as to be ignored if not OnPrem or not in-Cloud. And I guess MS just didn't want to add that.
As mentioned, the solution for your scenario would be to use pre-processor directives. This is something that we have on the backlog for the AL language.
If you have alternative suggestions to propose for handling this scenario, please post this on our Ideas forum at https://aka.ms/BusinessCentralideas, or vote up the idea if its already there. We're constantly monitoring top Ideas and will consider them for a future release.
Finally, if you are looking for a solution based on what other developers from the community have done on similar scenario, please use one of the following resources: Business Central Community mibuso forum Dynamics User Group
I will close this issue as by-design because the scope attribute is behaving as expected.
What do you mean "to use pre-processor directives"?
What do you mean "to use pre-processor directives"?
https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/directives/devenv-directives-in-al