与 NuGet 捆绑的本机 dll 的输出目录

Output Directory of native dll bundled with NuGet

我正在尝试构建一个包含本机 DLL 的 NuGet 包,当项目使用该包时,这些 DLL 将被放置在输出文件夹中。我尝试使用 this question 的一些建议,但我总是 运行 遇到同样的问题。

我目前的NuGet包布局是这样的:

\build
  packageId.targets
  file1.dll
  file2.dll
\lib
  \netstandard1.4
    assembly.dll

packageId.targets的内容是:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <NativeLibs Include="$(MSBuildThisFileDirectory)\*.dll"/>
    <None Include="@(NativeLibs)" Link="$(RecursiveDir)$(Filename)$(Extension)">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

根据其他问题的答案,这应该会导致我的 DLL 被放置在使用该包的项目的 bin\Debug 目录中。然而,他们不是。相反,它们被放置在 bin\Debug\packages\packageId\build.

现在我做了很多实验,我注意到越来越多的奇怪行为,我无法理解:

现在我更不明白是怎么回事了。

我需要更改什么才能将 DLL 复制到 bin\Debug

在 NuGet 中处理特定于运行时的同意的新方法是使用 runtimes 文件夹来放置本机资产:

\lib
  \netstandard2.0
    ManagedWrapper.dll
\runtimes
  \win-x86
    \native 
     NativeThing.dll
  \win-x64
    \native 
     NativeThing.dll
  \linux-x64
    \native 
     libNativeThing.so
  \osx-x64
    \native 
     libNativeThing.dylib

如果包是从 .NET Framework 项目中使用的,您可能需要添加对 Microsoft.NETCore.Platforms 包的引用,该包提供运行时图 (runtimes.json) 以便 NuGet 提供正确的 RID如果您不使用基本 RID,则映射(例如 win10-x64 回退到 win-x64 资源)。