Fix issue #382 (multiple publish output files with same relative path) #1234
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #382: On Windows, runtime files from backend packages are currently flattened during copy. This means that all files from subfolders end up in the same output directory, causing conflicts when multiple files share the same name.
Proposed fix
Correct the file
LLamaSharpBackend.props
as shown in the changes included in this PR.When building for Windows, and after installing the Windows-specific backend packages, make sure to add
ExcludeAssets="Native"
to thePackageReference
in the.csproj
, as shown below:Although
ExcludeAssets="Native"
is strictly necessary only for Windows backends when building on Windows, it shouldn’t cause issues for other backends. To be safe, it can be applied to all imported backend packages. I have tested this with bothLLamaSharp.Backend.Cpu
andLLamaSharp.Backend.Android
installed in the same MAUI project. This attribute tells MSBuild not to copy the runtime files from the NuGet package to the output directory, because copying is already handled correctly in theLLamaSharpBackend.props
file updated in step 1.How to Apply this fix before it is merged
If you urgently need to fix this issue, you can temporarily apply this change by copying the corrected
LLamaSharpBackend.props
content (from step 1) into each backend package directory, e.g.:and then import the package as indicated in step 2.
Note: this modification will be lost if the package is updated.
Future improvements:
Avoid using the default
Runtimes
folder, since MSBuild always flattens its contents building for windows causing conflicts. Using a custom folder for runtime files would eliminate the need to setExcludeAssets="Native"
in the package reference, and then change theLLamaSharpBackend.props
file to correctly fetch runtime files from the custom folder.Tests
I tested this fix on a limited scenario with a MAUI project having both
LLamaSharp.Backend.Cpu
andLLamaSharp.Backend.Android
installed. The goal was to ensure the app works on both types of devices. Given the large heterogeneity of the backends, I hope this fix will work for other backends as well.