Why and how to rename all AL-files of your app with the āCRS AL Language Extensionā
First of all, this is my first post of this new year, so Iād like to take this opportunity to wish you all the best and happiness for 2020! Last year, I did a post on my new hobby ā3D Printingā. Well, now weāre a year later, Iām still printing almost full time 24/7, so let me wish you all the best with some 3D Printed goodies I did for Xmas ;-).

So now ā āletās get startedā with ..
Why would I rename all my AL-files?
Well ā because of Microsoft and their new (upcoming) code analysis rule about file name conventions. You might already have complied with their previous conventions, and ⦠they will change. Even better: they actually already changed .. Just read here:
In the āoldā days, Microsoft wanted you to name the files including the object numbers. But not anymore.
This doesnāt really have to be a problem .. because today, we can freely choose however we want to name our files.
But that will change (a bit) ā¦
If you use the insider version of the AL Language Extension for VSCode, youāll see that we will get new code analysis rules that check the file name. This is an example that I had with my waldo.restapp I recently blogged about:

It doesnāt matter what my previous naming convention was ā the result is that all of a sudden, te compiler is going to have an opinion about it and will identify it as a āproblemā. It even calls it āincorrectā, not just ānot following the guidelinesā or whatever.. ;-).
Why would I care?
Well, if you donāt care .. then donāt! Just put rule AA0215 in your custom coderules and move on with your life ;-).
But I care. I want to comply with as many coderules .. as long as they donāt āhurtā me or my company. Thatās why we have a simple step in the build pipelines of our company: if any coderule would fail with an error or warning ā the code is not accepted by the build. And admittedly ā this is a good naming convention, anyway. So .. letās comply!
Waldoās CRS AL Language Extension
As you might know ā I created a VSCode Extension that makes it possible to easily handle file naming conventions. Because of these new guidelines (and coderules), I recently added a new option āObjectTypeShortPascalCaseā so that now itās also possible to handle it the correct way with settings in this extension.
BUT
Donāt rename your files by just invoking the command āRename All Filesā ā DONāT:

Because:
- You might change all your code history
- You might have wrong settings
- You might not be able to rollback and rethink ..
So, let me try to give you the safest way for you to rename all your files
Iām going to assume you are source-controlling your code here. If not .. I donāt even want to talk to you ;-).
Just kidding ā if not, just quickly initialize a git repo from the current state of your code. You might want to revert all changes you did .. and this gives you a way to do that. Honestly, this particular rename I did for this blog, I did 3 times .. just saying ;-).
1 ā Create a new branch
Before you do any coding, you should branch out. Same with this: just create your own snapshot of changes to work in. You canāt be too careful ..
You created it? Well, now youāre safe. Any kind of mistake within the next steps ā just remove the branch, create a new one, and start fumbling again ;-).
2 ā Change the setup
I think this is a good setup for the new filename conventions:
"CRS.FileNamePattern": "..al", "CRS.FileNamePatternExtensions": "..al", "CRS.FileNamePatternPageCustomizations": "..al", "CRS.OnSaveAlFileAction": "Rename", "CRS.RenameWithGit": true, "CRS.ObjectNameSuffix": " WLD",
Notice that there is no property āRemoveSuffixFromFilenameā or āRemovePrefixFromFilenameā. These properties invoke an extra procedure after renaming, to make sure you have no prefix in the filename anymore. Thing is ā it would make the name not comply again with the naming convention of Microsoftās coderule, unfortunately.
3 ā No Multiroot
Also notice the ārenamewithgitā setting. This is important, but a difficult one. If you donāt set this to ātrueā, any rename would result in a ādeleteā and ācreateā of your file ā meaning you would lose all the history of your files.
In my world of DevOps and Source Control, this is unacceptable. Really unacceptable. I want my history kept at all times! So, this setting is going to make sure you rename with git (āgit mvā).
Now ā in all honesty ā I have spent too much time already to make this setting as stable as at all possible. And it still isnāt. Sometimes, it just doesnāt do what itās supposed to do. Known issues are still:
- new files in combination with a multiroot workspace, it acts crazy (just deletes the content)
- With the ārename allā, it seems to be too fast sometimes, which fails the rename, which loses the history, which makes me angry ;-).
For the first, I have built in some fail saves, which basically will NOT rename with git of you have a multiroot workspace (not my preferred option, but for now, I have to give up on this ā spent too much time already :'( ) ..
And the second ā thatās why I write this blogpost ;-). How can you still rename all your files successfully, even when it would fail on your first attempt.
But ā to solve the first (you DO want to ārenamewithgitā), just avoid using multiroot workspaces. If you have multiple workspaces open, just close VSCode, and open that workspace of that one app you would like to rename all files from.
4 ā Commit these settings!
You might want to revert to this very version of this set of files when any of the next steps would fail for some reason or another. So please, commit now!
5 ā Rename ā All Files
Now is the time to start renaming all your files.

Remember you set the ārenamewithgitā, AND youāre not working multiroot, so it is going to try to rename all with git. Indeed: try! Because more than likely, āsomeā will succeed, and āsomeā will fail. If you have failed ones, it will show the ācrs-al-languageā output like this:

It seems that one process is blocking another to execute decently .. and because of that, it is actually going to rename the classic way, which would mean, it doesnāt preserve your git history.
When the complete rename is done, you should also have a look at the Source Control pane. If you have fail-messages, you should get some files in āStaged Changesā and some in āChangesā

Well: Staged are fine, and the ones in āChangesā, youāll need to retry. Do this by āDiscard All Changesā

And āDiscard All x Filesā

Now, you basically only renamed the ones that were able to rename, and you staged them. The ones that failed are restored to their original state, which still has all history, but are not renamed. So ..
6 ā Repeat ā¦
itās obvious .. this is where you repeat. So, rename again, and discard the changes if you have failed ones. And keep doing that, until all files ended up in your staged area (the āRā in the back indicates that you renamed the file):

7 ā Commit, PullRequest ā¦
And this means: youāre done. Time to commit and pullrequest your changes to your master/release/dev.. .
Conclusion
Iām not proud of this workaround ā Iād like to see it ājustā work. But when it comes to ārenaming or moving files with gitā, there seems something odd. I mean, think about it ā a simple rename in the VSCode Explorer window also ends up with a āDelete/Untrackedā, meaning ā you lose history.

A drag&drop to a new folder as well.

So ā just my conclusion ā if the VSCode wizards are not able to solve this simple ārenameā issue ā why would I be able to do it better than I already did ;-).
If this is useful to you! It was for me 
This was originally posted here.

Like
Report
*This post is locked for comments