AL icon indicating copy to clipboard operation
AL copied to clipboard

[Scope('OnPrem')] don't works

Open ghost opened this issue 6 years ago • 11 comments

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 : image

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

ghost avatar Jul 10 '20 08:07 ghost

How can it possibly work for cloud deployment when that function is not available/usable in the cloud...?

dzzzb avatar Jul 10 '20 13:07 dzzzb

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.

ghost avatar Jul 10 '20 14:07 ghost

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.

dzzzb avatar Jul 10 '20 14:07 dzzzb

That's exactly right.

ghost avatar Jul 10 '20 14:07 ghost

What is the use of [Scope('OnPrem')] if it's not ignored in cloud ?

CyrilleJsmt avatar Jul 10 '20 14:07 CyrilleJsmt

[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

qutreson avatar Jul 10 '20 14:07 qutreson

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?

ghost avatar Jul 10 '20 14:07 ghost

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.

dzzzb avatar Jul 10 '20 14:07 dzzzb

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.

qutreson avatar Jul 10 '20 15:07 qutreson

What do you mean "to use pre-processor directives"?

ghost avatar Jul 10 '20 15:07 ghost

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

B-Wissler avatar Feb 20 '24 07:02 B-Wissler