Skip to content

Commit d5bc3e0

Browse files
authored
[msbuild] Don't try to create an output file on Windows using a full path. (#21486)
Fixes this warning: > [...]\packs\Microsoft.iOS.Sdk.net9.0_18.0\18.0.9731-ci.dev-rolf\tools\msbuild\iOS\Xamarin.Shared.targets(755,3): Access to the path 'C:\Users\rolf\Library\Caches\Xamarin\mtbs\builds\BundleStructure\e3602c179d4eceb04f35658ffc4180192072542b74da729d64a6505c255de589\obj\Debug\net9.0-ios\ios-arm64' is denied.
1 parent 0bac6d4 commit d5bc3e0

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

msbuild/Xamarin.MacDev.Tasks/Tasks/CompileEntitlements.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class CompileEntitlements : XamarinTask, ITaskCallback, ICancelableTask {
5454
public string BundleIdentifier { get; set; } = string.Empty;
5555

5656
[Required]
57+
[Output] // this is required to create an output file on Windows. Note: this is a relative path.
5758
public ITaskItem? CompiledEntitlements { get; set; }
5859

5960
public ITaskItem [] CustomEntitlements { get; set; } = Array.Empty<ITaskItem> ();
@@ -524,16 +525,16 @@ public override bool Execute ()
524525
/* The path to the entitlements must be resolved to the full path, because we might want to reference it from a containing project that just references this project,
525526
* and in that case it becomes a bit complicated to resolve to a full path on disk when building remotely from Windows. Instead just resolve to a full path here,
526527
* and use that from now on. This has to be done from a task, so that we get the full path on the mac when executed remotely from Windows. */
527-
CompiledEntitlements = new TaskItem (Path.GetFullPath (CompiledEntitlements!.ItemSpec));
528+
var compiledEntitlementsFullPath = new TaskItem (Path.GetFullPath (CompiledEntitlements!.ItemSpec));
528529

529530
if (Platform == Utils.ApplePlatform.MacCatalyst) {
530-
EntitlementsInSignature = CompiledEntitlements;
531+
EntitlementsInSignature = compiledEntitlementsFullPath;
531532
} else if (SdkIsSimulator) {
532533
if (compiled.Count > 0) {
533-
EntitlementsInExecutable = CompiledEntitlements;
534+
EntitlementsInExecutable = compiledEntitlementsFullPath;
534535
}
535536
} else {
536-
EntitlementsInSignature = CompiledEntitlements;
537+
EntitlementsInSignature = compiledEntitlementsFullPath;
537538
}
538539

539540
return !Log.HasLoggedErrors;
@@ -569,7 +570,13 @@ bool SaveArchivedExpandedEntitlements (PDictionary archived)
569570

570571
public bool ShouldCopyToBuildServer (ITaskItem item) => true;
571572

572-
public bool ShouldCreateOutputFile (ITaskItem item) => true;
573+
public bool ShouldCreateOutputFile (ITaskItem item)
574+
{
575+
// EntitlementsInExecutable and EntitlementsInSignature are full paths on macOS,
576+
// which doesn't work correctly when trying to create such output files on Windows.
577+
var isFullPath = item == EntitlementsInExecutable || item == EntitlementsInSignature;
578+
return !isFullPath;
579+
}
573580

574581
public IEnumerable<ITaskItem> GetAdditionalItemsToBeCopied ()
575582
{

0 commit comments

Comments
 (0)