Hi @Jack , Welcome to Microsoft Q&A,
According to the problem you described, although the native libraries of the NuGet package are correctly placed in the runtimes\win10-arm64\native
directory, they are not automatically loaded at runtime. This means that the .NET runtime cannot find these dependent native libraries unless they are manually added to the PATH
of the environment variable.
You can modify the project file (.csproj) to ensure that the native libraries are copied to the root directory of the output directory instead of placing them in a subdirectory (such as runtimes\win10-ARM64\native), so that the .NET runtime can find these libraries directly.
You can add the following content to the .csproj file to ensure that the native libraries are copied correctly:
<ItemGroup>
<None Update="runtimes\win10-arm64\native\*.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
</ItemGroup>
This configuration will copy all .dll files in the runtimes\win10-arm64\native directory to the root of the output directory to ensure that they can be loaded correctly.
Use .targets files to automatically copy native libraries In NuGet packages, you can use .targets files to define automatic copying of native libraries to the output directory when building.
You can add similar configuration to the .targets file of the NuGet package to ensure that native libraries are automatically copied to the root of the output directory:
<Project>
<ItemGroup>
<Content Include="runtimes\win10-arm64\native\*.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
Make sure the .targets file is published with the NuGet package, and the NuGet package will automatically apply these configurations when it is referenced.
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.