Xcode project build automation setting up app group

I have recently updated xcodeAPI from the older version provided by one signal to the latest version provided by unity on bitbucket.
This new version added support for Capabilities (setting push notification, In app Purchase, etc… programatically).
I am now running into problems getting App Group setup programatically, something that was working just fine in the older version of xcodeAPI.

In my PostProcessBuild function, amongst setting up all the other PBXProject option I do:

ProjectCapabilityManager projectManager = new ProjectCapabilityManager(projectPath, entitlementsPath, targetGuid);
PBXProject.AddCapability(targetGuid, PBXCapabilityType.AppGroups)
projectManager.AddAppGroups(new string[] {"group.my_company.onesignal"});  

it used to work on the one signal postprocessbuild with this code:

if (entitlements.root["com.apple.security.application-groups"] == null) 
        var groups = entitlements.root.CreateArray("com.apple.security.application-groups");
        groups.AddString("group." + PlayerSettings.applicationIdentifier + ".onesignal");

That is not working, I am not sure what I am missing. I am assuming that the new xcodeAPI works differently, but there is very little example on how to use it.

string projectPath = PBXProject.GetPBXProjectPath(buildPath);

string entitlementsPath = "Unity-iPhone.entitlements"; 

PBXProject project = new PBXProject();

//This is the same as going manually to Signing & Capabilities > pressing "+ Capability" > App Groups, then adding an entry for the desired group
ProjectCapabilityManager projectManager = new ProjectCapabilityManager(projectPath, entitlementsPath, null, project.GetUnityMainTargetGuid());
project.AddCapability(project.GetUnityMainTargetGuid(), PBXCapabilityType.AppGroups, entitlementsPath);
projectManager.AddAppGroups(new string[] {"group.com.yourcompany.whaterver"});