Tag: VS Code

  • Stop tracking files in Git with VS Code

    git

    Git provides a mechanism to ignore certain files in a repository, that’s the job of the .gitignore file. You can also stop tracking files in Git that have already been committed, but with a little bit more work.

    Simply create this file in the workspace root and list out all the files and directories that we don’t want Git to track.

    My .gitignore file will typically contain:

    .alpackages
    .vscode
    *.app

    A .gitignore file with the above contents will ignore both the .alpackages and .vscode folders, and any file with the extension .app.

    .alpackages – This contains the apps your app depends on and gets created when you download symbols.

    .vscode – This contains all your user specific workspace and environment settings such as launch.json, user workspace settings etc.. you don’t want to share this.

    *.app – this is you compiled app files and will be generated every time you compile.. this doesn’t belong in your repository.

    I’ll usually also have a scripts folder where I’ll put my PowerShell script to create my local Docker container, you may or may not want to share something like this in your repository. If not, add it to .gitignore.

    So far so good, but what if you or one of your team has already committed some files that shouldn’t be tracked? If Git is already tracking a file, adding it to .gitignore will do absolutely nothing.

    So how do we fix this?

    Simply deleting the files and committing wont resolve this as Git will continue to track the file. Once we put the file back (i.e. recreate the launch.json) Git will start tracking it again.

    We not only need to delete the files, we also need to remove the files from the Git index to stop tracking files in Git.

    The VS Code command pallet won’t help because the built in Git extension doesn’t have a command for this, so we’ll have to head over to our terminal and talk to Git directly.

    For an example, lets say no .gitignore file had been created for the initial commit and Git is now tracking every file in our repository. We want to create the .gitignore file shown above and stop tracking the directories and files specified in it.

    The command git rm can be used to remove tracked files from your repository index. To use this command on a directory, we need to add the recursive switch -r.

    From the VS Code terminal type the following commands:

    PS> git rm -r .alpackages
    PS> git rm -r .vscode
    PS> git rm *.app

    As we can see the command will accept the wildcard (*) and delete all .app files.

    At this point you can see that Git has staged all the file deletes:

    stop tracking files in Git

    Next up, create a file named .gitignore and add entries for the lines you want to ignore:

    gitignore

    Now stage the .gitignore file and commit your changes, before synchronizing with remote. The files will be removed from the remote, and any local repositories the next time they do a pull request. Of course, the files will still be visible in your git history if you ever need to recover anything.

    When you regenerate your launch.json (or paste is in from your backup) and download symbols, you’ll notice git is no longer tracking these files.

  • Sorry, that didn’t work – Debugging AL from VS Code

    Sorry that didn't work
    So you’ve installed your NAV 2018 developer environment, fired up VS Code, pressed F5 (publish and debug), the Web Client starts to load and…

    Sorry, that didn’t work
    An error has occurred

    If you look in the Windows Event Viewer and find the message below, read on for the solution:

    Server instance: DynamicsNAV110
    Tenant ID:
    <ii>User: BLANKED\Dan.Kinsella
    Type: System.InvalidOperationException
    Message: <ii>Dynamic operations can only be performed in homogenous AppDomain.</ii>
    StackTrace:
    at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)
    at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
    at Microsoft.Dynamics.Nav.Service.Dev.Web.Controllers.DebuggerHub.OnDebuggeeConnected(Object sender, DebugSessionStartEventArgs eventArgs)
    at Microsoft.Dynamics.Nav.Runtime.Debugger.DebugRuntimeManager.OnDebuggingSessionStarted(DebugSessionStartEventArgs e)
    at Microsoft.Dynamics.Nav.Runtime.Debugger.DebugRuntimeManager.CreateRuntime(String debuggingContext, NavSession session, Boolean waitForDebugAdapterConfiguration)
    at Microsoft.Dynamics.Nav.Runtime.NavSession.StartDebuggingSession(String debuggingContext, Boolean waitForDebugAdapterConfiguration)
    at Microsoft.Dynamics.Nav.Service.NSService.OpenConnection(ConnectionRequest connectionRequest)
    at SyncInvokeOpenConnection(Object , Object[] , Object[] )
    at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
    at Microsoft.Dynamics.Nav.Service.ServiceOperationInvoker.ErrorMappingCombinator(ServiceOperation innerOperation, NSServiceBase serviceInstance, MethodBase syncMethod, Object[] inputs, Object[]& outputs)
    Source: System.Core
    HResult: -2146233079
    </ii>

    The solution

    To enable AL debugging from VS Code we need to change the NetFx40_LegacySecurityPolicy setting in the Microsoft.Dynamics.Nav.Server.exe.config file to false.

    The Microsoft.Dynamics.Nav.Server.exe.config file is found in the Dynamics NAV service install directory, which (if you accepted the default) will be in the following location:

    C:\Program Files\Microsoft Dynamics NAV\110\Service\Microsoft.Dynamics.Nav.Server.exe.config

    Search the config file for the NetFx40_LegacySecurityPolicy setting, and change the enabled property to false:

    <NetFx40_LegacySecurityPolicy enabled="false"/>
    After restarting the service tier, try again and the Web Client should now open with a debug session.