dotnet / dotnet/xcsync

Sync from XCode not working in Native Embedding project

Open
#236 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
25
Forks
10
Avg merge
12h 50m
Merged PRs (30d)
10

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Apple platform

iOS

### Framework version

Other

### Describe the bug

I am trying to use xcsync with a .NET for iOS project with [MAUI native embedding](https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/native-embedding?view=net-maui-10.0&pivots=devices-android#enable-net-maui-support) enabled. While the `xcsync generate` command works fine, the `xcsync sync` command breaks with the following error:

```
Unhandled exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '/Users/builduser/Projects/TestApp.iOS/Platforms/iOS/Entitlements.plist'.
```

This seems to be because the sync tool expects the platforms folder to be there if the Maui flag is set, which is not the case in a Maui native embedding project.

Looking into the code it seems for a .NET -> XCode sync the tool checks for the actual presence of the Platforms/iOS or Platforms/MacCatalyst folders to determine the project type and folders to read/write:

https://github.com/dotnet/xcsync/blob/cb2f99589461549cec130aa3e01c35bff383e0fb/src/xcsync/SyncContext.cs#L162-L169

While for the XCode -> .NET sync it just checks the MAUI flag to determine the folder to read/writer:

https://github.com/dotnet/xcsync/blob/cb2f99589461549cec130aa3e01c35bff383e0fb/src/xcsync/SyncContext.cs#L486-L494

### Expected Behavior

The tool should not be trying to read/write to the non-existing Platforms/iOS and Plaforms/MacCatalyst folder if it's handling a MAUI native embedding enabled .NET for iOS project (not a full MAUI project)

### Steps To Reproduce

[Reproduction repo](https://github.com/leonluc-dev/xcsync-issue-repro)

* Open the solution
* Build/run it once
* Use the `xcsync generate -f --open --project ReproApp.csproj` command to generate and open the xcode project
* Close the Xcode project and use `xcsync sync --project ReproApp.csproj` command

### Exceptions (if any)
```
Unhandled exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '/Users/builduser/Projects/TestApp.iOS/Platforms/iOS/Entitlements.plist'.
at System.IO.FileSystem.TryCloneFile(String sourceFullPath, String destFullPath, Boolean overwrite, Boolean& cloned)
at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite)
at System.IO.Abstractions.FileWrapper.Copy(String sourceFileName, String destFileName, Boolean overwrite)
at xcsync.Workers.CopyFileWorker.ConsumeAsync(CopyFileMessage message, CancellationToken cancellationToken) in /_/src/xcsync/Workers/FileWorker.cs:line 77
at Marille.Hub.DeliverAtMostOnce[T](Channel`1 channel, IWorker`1[] workersArray, Message`1 item, Nullable`1 timeout) in /_/src/Marille/Hub.cs:line 91
at Marille.Hub.ConsumeChannel[T](TopicConfiguration configuration, Channel`1 ch, IErrorWorker`1 errorWorker, IWorker`1[] workersArray, TaskCompletionSource`1 completionSource, CancellationToken cancellationToken) in /_/src/Marille/Hub.cs:line 143
at Marille.TopicInfo`1.CloseChannel() in /_/src/Marille/TopicInfo.cs:line 69
at Marille.TopicInfo`1.DisposeAsyncCore() in /_/src/Marille/TopicInfo.cs:line 90
at Marille.TopicInfo.DisposeAsync() in /_/src/Marille/TopicInfo.cs:line 46
at Marille.Topic.DisposeAsyncCore() in /_/src/Marille/Topic.cs:line 72
at Marille.Topic.DisposeAsync() in /_/src/Marille/Topic.cs:line 78
at Marille.Hub.CloseAllAsync() in /_/src/Marille/Hub.cs:line 321
at xcsync.SyncContext.SyncAsync(CancellationToken token) in /_/src/xcsync/SyncContext.cs:line 35
at xcsync.Commands.SyncCommand.Execute() in /_/src/xcsync/Commands/SyncCommand.cs:line 20
at System.CommandLine.Invocation.AnonymousCommandHandler.InvokeAsync(InvocationContext context)
at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<b__18_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<b__5_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<b__0>d.MoveNext()
```
### .NET Version info

.NET 10.0.103
xcsync 0.1.0-preview.24509.2
VS Code 1.109

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.