Skip to content

Commit

Permalink
Improve error reporting.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne committed Dec 9, 2024
1 parent 3c8601e commit 70211f0
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/DetectSigningIdentity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Collections.Generic;
Expand Down Expand Up @@ -192,16 +193,28 @@ public bool HasEntitlements {
} else if (string.IsNullOrEmpty (CodesignEntitlements?.ItemSpec)) {
// If no CodesignEntitlements was specified, we don't have any entitlements
hasEntitlements = false;
} else {
} else if (TryReadCodesignEntitlements (out var entitlements)) {
// Check the file to see if there are any entitlements inside
var entitlements = PDictionary.FromFile (CodesignEntitlements.ItemSpec);
hasEntitlements = entitlements.Count > 0;
}
}
return hasEntitlements.Value;
}
}

bool TryReadCodesignEntitlements ([NotNullWhen (true)] out PDictionary dictionary)
{
dictionary = null;
var path = CodesignEntitlements!.ItemSpec;
try {
dictionary = PDictionary.FromFile (path)!;
return true;
} catch (Exception ex) {
Log.LogError (MSBStrings.E0113 /* Error loading Entitlements.plist template '{0}': {1} */, path, ex.Message);
return false;
}
}

class CodeSignIdentity {
public X509Certificate2 SigningKey { get; set; }
public MobileProvision Profile { get; set; }
Expand Down Expand Up @@ -344,7 +357,9 @@ void ValidateAppEntitlements ()
}
});

var requestedEntitlements = PDictionary.FromFile (requestedEntitlementsPath)!;
if (!TryReadCodesignEntitlements (out var requestedEntitlements))
return;

var provisioningEntitlements = detectedIdentity.Profile?.Entitlements;
foreach (var kvp in requestedEntitlements) {
var key = kvp.Key;
Expand Down

0 comments on commit 70211f0

Please sign in to comment.