-
Notifications
You must be signed in to change notification settings - Fork 480
Description
Description
Context
When building or publishing a WinUI 3 (Windows App SDK) or MAUI (Windows) project that references LLamaSharp.Backend.Cpu, the build fails due to conflicting native assets.
Root Cause
LLamaSharp.Backend.Cpu includes multiple versions of the same DLLs (e.g., llama.dll) optimized for different instruction sets (avx, avx2, etc.). The WinUI/MSIX packaging system performs a strict uniqueness check on the "Relative Path" of every file being bundled. Since multiple copies of llama.dll exist in the target output, the packaging logic flags them as fatal collisions.
Observed Errors
- NETSDK1152:
Found multiple publish output files with the same relative path. - APPX1101:
Payload contains two or more files with the same destination path...
Proposed Fix
The fix involves updating LLamaSharp.Runtime.targets to conditionally relax these checks and deduplicate the payload list when a WinUI project is detected.
Verified Changes in LLamaSharp.Runtime.targets:
<!-- WinUI 3 / Appx Duplicate File Fix -->
<PropertyGroup Condition="'$(UseWinUI)' == 'true' or '$(IsWinUIApp)' == 'true'">
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
<AppxPackageAllowDuplicates>true</AppxPackageAllowDuplicates>
<AppxPackageValidationEnabled>false</AppxPackageValidationEnabled>
<DisableAppxChecks>true</DisableAppxChecks>
</PropertyGroup>
<Target Name="DeduplicateAppxPackagePayload" BeforeTargets="_ValidateAppxPackagePayload" Condition="'$(UseWinUI)' == 'true' or '$(IsWinUIApp)' == 'true'">
<ItemGroup>
<_AppxPackagePayloadFiltered Include="@(AppxPackagePayload)" />
<AppxPackagePayload Remove="@(AppxPackagePayload)" />
</ItemGroup>
<RemoveDuplicates Inputs="@(_AppxPackagePayloadFiltered)">
<Output TaskParameter="Filtered" ItemName="AppxPackagePayload" />
</RemoveDuplicates>
</Target>Reproduction Steps
Reproduction Steps
(Paste this into the second box)
1. Create a new "WinUI 3 in Desktop" (WinAppSDK) project.
2. Add a Reference to `LLamaSharp` (core) and `LLamaSharp.Backend.Cpu`.
3. Attempt to Build or Publish the project for `x64`.
4. Observe the `NETSDK1152` or `APPX1101` errors in the Build Output.Environment:
- OS: Windows 10/11
- Framework: .NET 8.0/9.0
- Library: LLamaSharp v0.25.0
- Backend: LLamaSharp.Backend.Cpu
Environment & Configuration
- Operating system: Windows 11
- .NET runtime version: .NET 8.0 / .NET 9.0
- LLamaSharp version: v0.25.0
- CUDA version: N/A (Issue relates to LLamaSharp.Backend.Cpu)
- CPU & GPU device: Standard x64 CPU (Issue occurs during build/package phase)
Known Workarounds
A temporary workaround is to manually add the following properties to the WinUI/MAUI .csproj file to suppress the strict uniqueness checks:
<PropertyGroup>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
<AppxPackageAllowDuplicates>true</AppxPackageAllowDuplicates>
<AppxPackageValidationEnabled>false</AppxPackageValidationEnabled>
</PropertyGroup>