Search code examples
c#linuxnugetexternal.so

Problems with external .so libaries in nuget package


I've got a nuget package which contains some libraries (.dll and .so). We need the .dll for our windows environment and the .so for the Linux environment. I checked if both files are packed in the nuget and this is the case.

If I install this nuget into a webservice and start it, the .dll gets placed in the correct place (the executable path). However the .so files does not get copied, even if the webservice is started in the Linux environment. If this is the case the .dll is also copied into the executable path.

This is how I import the files inside the nuget project:

 <ItemGroup>
    <Content Include="..\..\Lib\win64\dll\ericapi.dll">
        <Link>ericapi.dll</Link>
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        <Pack>true</Pack>
        <PackagePath>lib\$(TargetFramework)</PackagePath>
    </Content>
</ItemGroup>

<ItemGroup>        
    <Content Include="..\..\Lib\lin64\lib\libericapi.so">
        <Link>libericapi.so</Link>
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        <Pack>true</Pack>
        <PackagePath>lib\$(TargetFramework)</PackagePath>
    </Content>
</ItemGroup>

this is a screenshot of the lib directory of my nuget: enter image description here

If the Webservice is started locally only the .dll gets copied into "bin\Debug\net8.0"

Why is this the case. Can only .dll files be copied this way?


Solution

  • I think i just got it solved. I replaced "PackagePath" with "PackageCopyToOutput". With this setup i´ve got all the files in the right direcotry, even on Linux:

    <ItemGroup>
        <Content Include="..\..\Lib\win64\dll\ericapi.dll">
            <Link>ericapi.dll</Link>
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <PackageCopyToOutput>true</PackageCopyToOutput>
            <Pack>true</Pack>
        </Content>
    </ItemGroup>
    
    <ItemGroup>        
        <Content Include="..\..\Lib\lin64\lib\libericapi.so">
            <Link>libericapi.so</Link>
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <PackageCopyToOutput>true</PackageCopyToOutput>
            <Pack>true</Pack>
        </Content>
    </ItemGroup>