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.
Any time a package is installed or reinstalled, which includes being installed as part of a restore process, NuGet also installs any additional packages on which that first package depends. Those immediate dependencies might then also have dependencies on their own, which can continue to an arbitrary depth.
Select the Tools > NuGet Package Manager > Package Manager Console menu command. Once the console opens, check that the Default project drop-down list shows the project into which you want to install the package. If you have a single project in the solution, it is already selected.
The term "managed code" usually refers to code written in a managed language, such as Java or C#. The term "unmanaged code" usually refers to code written in an unmanaged language, such as C or C++. If you're coming from the . NET world, "managed" probably means C# or VB.NET, and "unmanaged" probably means C or C++.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With