Skip to content

Fix issue #382 (multiple publish output files with same relative path) #1234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

LucaMaccarini
Copy link

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

  1. Correct the file LLamaSharpBackend.props as shown in the changes included in this PR.

  2. When building for Windows, and after installing the Windows-specific backend packages, make sure to add ExcludeAssets="Native" to the PackageReference in the .csproj, as shown below:

<PackageReference Include="LLamaSharp.Backend.Cpu" Version="0.24.0" ExcludeAssets="Native"/>

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 both LLamaSharp.Backend.Cpu and LLamaSharp.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 the LLamaSharpBackend.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.:

C:\Users\<your user>\.nuget\packages\<llamasharp backend>\<version>\build\netstandard2.0\<llamasharp backend>.props

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 set ExcludeAssets="Native" in the package reference, and then change the LLamaSharpBackend.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 and LLamaSharp.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.

@martindevans
Copy link
Member

Thanks for looking into this. #382 has been a long standing issue that a few people (including me) have had a look at but failed to solve, I'm happy to see the fix turns out to be so simple!

I'll find some time to test this out soon, I'd really like to get it into the next update if possible.

Would you be interested in developing a followup PR with your suggested improvements? Removing the extra installation step and making it just work would be fantastic.

@LucaMaccarini
Copy link
Author

Glad I could help, this issue had been around for a while, let’s see if the tests confirm the fix.
At the moment, with my fix, the runtimes are packaged into the NuGet packages only under the LLamaSharpRuntimes directory, but then imported into the project under the runtimes folder. This way, nothing should change on the code side and the runtimes end up where they’re expected to be.

One note

I’m not sure why, but the last time I worked on this bug I was able to pack the NuGets with the original paths. This time, however, I had to adjust them. In all the .nuspec files the src attribute of the <file> elements no longer starts with runtimes/ but with ../.

For example:
<file src="../deps/noavx/ggml.dll" target="LLamaSharpRuntimes\win-x64\native\noavx\ggml.dll" />

I hope this doesn’t break the way you build the packages, if it does, please let me know and I’ll restore the src paths to their previous state.

Testing

As before, I tested with a MAUI project using LLamaSharp.Backend.Cpu and LLamaSharp.Backend.Android. This time, I added the packages using the usual NuGet Package Manager GUI, and it was not necessary to use ExcludeAssets="Native".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dotnet publish issue - multiple publish output files with same relative path
2 participants