RSS

Business Central: Multiversion Branch With Preprocessor Directives

07 Apr

Like many companies nowadays we have bunch of customers with different Business Central versions that we need to support.

On top of this many of us tries to “create  money while we sleep” by creating stand alone apps that we could reuse/resell to new customers and perhaps eventually put them on AppSource in the next step.

This means that we need to support/maintain our standalone apps in multiple versions.

The first idea that comes to mind is to create different version branches for our standalone apps and then we cherry pick each update to each version branch.

Is this a good solution? NO WAY!

As it is our team just learned half a year ago on how to do proper pull requests and still struggle with setting the correct devops status when pull request completes.

Should the same team be responsible to remember, “Oh it is this app I’m working on, then I should cherry pick this change to all the other branches”. I’m sorry to say but that’s not gonna happen. That would be asking for trouble.

The ideal thing would be if we only needed to handle/maintain ONE version branch that works for many versions.

This is actually possible with preprocessor directives in AL .

By using this we get a selective statement of how we would like the compiler to run. This means that we can actually pick which code we want the compiler to compile by using a statement.

When we pick which version we would like to compile for we specify our statement as a preprocessorSymbol in the app.json. Here I have specified to use CLEAN22, that should be used with my BC 22 version.

After that we move on to the selective statement. In our code example we have done a simple page action that shows a message but different message depending on which preprocessorSymbols you have specified.

When we run this after compile we get the following message.

If we change the preprocessorsymbol to CLEAN18 it would instead give us the following:

This is also possible to do this at a larger extent. You could wrap in entire files with this. Example, a table is being deprecated and moved. The deprecated table can be wrapped into a #if CLEAN17, CLEAN18, CLEAN19, CLEAN20… and then you create a new file that should only work for new versions. I’m not saying you should, but that you could.

The latest use we had for this is the that the table “Item Cross Reference” is deprecated in BC22 and replaced by “Item Reference”

 
2 Comments

Posted by on 2023-04-07 in Okategoriserade

 

Tags: ,

2 responses to “Business Central: Multiversion Branch With Preprocessor Directives

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
The BC Docs Librarian

Tips and news for AL programmers

Stefan Maroń

Dynamics 365 Business Central

James Pearson

Thoughts about Dynamics 365 Business Central, Git, Azure DevOps, PowerShell, Automated Testing, Visual Studio Code...and maybe some other stuff

Roberto Stefanetti BLOG

MVP & MCT Microsoft Dynamics 365 Business Central, Powershell, Azure, SQL Server

JoeBrown

DevOps starts with culture!

Comments for DevOps ABCs Blog

Reflections from the ERP field

DevOps ABCs Blog

Reflections from the ERP field

Dynamics 365 Business Central for Partners

Reflections from the ERP field

Freddys blog

Learn something new... - then Teach someone!

Stefano Demiliani Technical Blog

Reflections from the ERP field

David Worthington's NAV Performance Blog

Micosoft Dynamics NAV Performance Testing & Optimization

Freddys Blog

Reflections from the ERP field

Marije Brummel Blog | Business Central, Azure and more...

Design Patterns, Performance, Clean Code

Vjeko.com

Ideas in the cloud

Goprowe AB

Reflections from the ERP field

ArcherPoint

Reflections from the ERP field

The NAV Viking´s Blog

- Sharing my experience in the Dynamics NAV world

Comments for

Reflections from the ERP field

Nav Can Be Fun

Its Really Fun to Work with Microsoft Dynamics Nav / D365 Business Central

%d bloggers like this: