Exercise - Source control with Git

Completed

This exercise is written to use the Cronus sample company from the US version of Business Central. You might need to make adjustments to the steps if you use the sample company from your country or region.

Scenario

You are a developer working for CRONUS International Ltd. You want to create a new AL extension, add it to version control with Git, and safeguard the code in Azure Repos.

Tasks

  • Create a new AL Extension

  • Add the source code to a local Git repository

  • Add Azure Repos as remote Git repository

  • Push the local Git repository to the remote repository

Steps

  1. Start Visual Studio Code.

  2. Select View > Extensions (Ctrl+Shift+X).

  3. Type AL Language in the Search Extensions in the Marketplace search box.

  4. Click the green Install button.

  5. Create a new AL Extension project. Select View > Command Palette... (Ctrl+Shift+P).

  6. Type AL: Go! in the search box and select the command from the list.

  7. Accept the suggested path (or enter another path).

  8. Select the latest target platform.

  9. Select Microsoft cloud sandbox as the development endpoint.

  10. Download the application symbols by selecting View > Command Palette... (Ctrl+Shift+P).

  11. Type AL: Download symbols in the search box and select the command from the list.

  12. If requested, provide your organizational credentials (Microsoft 365 account/Microsoft Entra ID account).

  13. Open the App.json file and change the name setting to Hello Business Central Change the publisher setting to Cronus International Ltd.

  14. Install Git (if not installed) using the Downloading Git page.

  15. In Visual Studio Code select View > SCM (Ctrl+Shift+G) to open the Source Control view.

  16. Click the Initialize Repository button to initialize a local repository for the current AL Extension.

  17. Your files are now displayed with a status U at the end, indicating Untracked. Right click the first .app file and select add to .gitignore. You can only do this from within the Source Control view, not in the Explorer view

  18. Repeat this process for every .app file and for the launch.json file.

  19. Select all files, right click, and select Stage Changes or click the + icon next to Changes. This action will add the files to the staging area.

  20. Add the message Initial Commit in the commit message box, and click the commit button (the check mark button) or press Ctrl+Enter

  21. Open your favorite web browser and open your Azure DevOps organization.

  22. Select the project Hello Business Central if you created it from the the video demonstration, or create a new project if that project isn't available.

  23. Click Repos in the left menu. You will see that the repository is empty, and that you can add code to the repository.

  24. Copy the https link that you can find in the Clone to your computer section.

  25. Open Visual Studio Code and press F1, and type Git: Add Remote... in the search box.

  26. Enter a remote name: origin

  27. Paste the URL you copied from Azure Repos in the remote URL box.

  28. Depending on your configuration Visual Studio Code will prompt you to log in into Azure DevOps with your Microsoft Account/Organizational Account. If this doesn't work, and Visual Studio Code still asks you to login with a username and a password, you can go back into Azure DevOps, and click the button Generate Git Credentials under the input box where you copied the repo URL. This allows you to copy a username and a password that you can use for Git instead of your standard account.

  29. If the remote repository is successfully linked in Visual Studio Code, you can click the Publish icon at the left bottom of your Visual Studio Code window. This button is a cloud icon with an arrow up. You will find it next to the master branch button.

These steps will publish your local code in Azure Repos.

  1. Open Azure DevOps, refresh the page and your code should be visible.

  2. Open Visual Studio Code, open the HelloWorld.al file and change Hello World in Hello Business Central in the Message function. Save your modifications (Ctrl+S).

  3. Open your Source Control view. The HelloWorld.al file should be visible as changed. Select the file and add the file to the staging area.

  4. Add a commit message and click the commit button.

  5. Now, push your changes to the remote repository. You can click the three dots ... to open a menu and select push. Or you can click the synchronization icon at the bottom of the window (same location as you clicked the publish icon). This action will synchronize. Therefore, a window will be visible that mentions that this action will perform a pull and a push. You can agree by clicking Yes.

  6. Open Azure DevOps and refresh the page and select the HelloWorld.al file. Your modifications should be visible.