I'm developing a .NET Core 2.1 library that depends on an unmanaged DLL. I'd like to include the unmanaged DLL in the NuGet package as well. The problem that I am running into is that if I try to specify all of the information in the .csproj
file, the dotnet build
process throws the following warning:
warning NU5100: The assembly 'content\lib\subdir\somedll.dll' is not
inside the 'lib' folder and hence it won't be added as a reference
when the package is installed into a project. Move it into the
'lib' folder if it needs to be referenced.
I know that I can embed the unmanaged DLLs by writing a .nuspec
(in fact, I have). However, it seems like I shouldn't need to write one with the latest .csproj
file format.
Question: How can I use the .csproj
file to embed unmanaged DLLs in a NuGet package?
<ItemGroup><None>
in the .csproj
file seems to include the files in the output directory but they do not make it into the NuGet package.<ItemGroup><Content>
in t he .csproj
file will get them added to the NuGet package but in the Content directory instead of in the Lib directory.If I really have to have both a .csproj
file and a .nuspec
file, what is the best practice for where to put the metadata? In t he .csproj
file? In the .nuspec
file? Maintain and sync both? Is there a something in the tool chain that can do this for me?
I'm working in Visual Studio Code V1.24, and .NET Core/dotnet V2.1.
You need to specify explicit package path metadata on the element so that the dll/so/dylib file ends up at the right place in the package so that it is recognised as runtime-specific native DLL:
<ItemGroup>
<None Include="unmanaged.dll" Pack="true" PackagePath="runtimes\win-x64\native" />
</ItemGroup>