使用csproj在NuGet程序包中包含非托管DLL

Ste*_*icz 3 nuget .net-core

我正在开发一个依赖于非托管DLL的.NET Core 2.1库。我也想在NuGet包中包含非托管DLL。我遇到的问题是,如果我尝试指定.csproj文件中的所有信息,则该dotnet build过程将引发以下警告:

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.
Run Code Online (Sandbox Code Playgroud)

我知道我可以通过编写一个.nuspec(实际上,我拥有)来嵌入非托管DLL。但是,似乎不需要用最新的.csproj文件格式编写文件。

问题:如何使用.csproj文件将非托管DLL嵌入NuGet包中?

  • <ItemGroup><None>.csproj文件中指定似乎将文件包含在输出目录中,但它们没有将其放入NuGet包中。
  • <ItemGroup><Content>.csproj文件中指定会将它们添加到NuGet包中,但添加到Content目录中,而不是Lib目录中。

如果我确实必须同时拥有一个.csproj文件和一个.nuspec文件,那么将元数据放在哪里的最佳实践是什么?他要.csproj归档吗?在.nuspec文件中?维护和同步两者?工具链中是否有可以帮助我的东西?

我正在使用Visual Studio Code V1.24和.NET Core / dotnet V2.1。

Mar*_*ich 7

您需要在元素上指定显式的包路径元数据,以便dll / so / dylib文件最终位于包中的正确位置,以便将其识别为特定于运行时的本机DLL:

<ItemGroup>
  <None Include="unmanaged.dll" Pack="true" PackagePath="runtimes\win-x64\native" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)