NuGet 警告 NU5131

References were found in the nuspec, but some reference assemblies were not found in both the nuspec and ref folder. Add the following reference assemblies:
- Add AssemblyName.dll to the ref/net472/ directory

问题

NuGet 具有一项功能,它允许包作者选择在编译时在使用此包的项目中可用的程序集。

如果未遵循所需的约定,则使用此包且具有 PackageReference 的项目在运行时可能会因缺少程序集而失败。

解决方案

nuspec 文件的 <references> 部分内的程序集的列表应在 ref/<tfm>/ 中存在匹配的程序集。

例如,考虑包含以下文件的包:

lib\net472\MyLib.dll
lib\net472\MyHelpers.dll
lib\net472\MyUtilities.dll

包作者想阻止包使用者编写直接调用 MyUtilities.dll 的代码,因此他们将以下内容添加到 nuspec 文件中:

<references>
    <group targetFramework="net472">
        <reference file="MyLib.dll" />
        <reference file="MyHelpers.dll" />
    </group>
</references>

使用 PackageReference 时,此包无法按预期方式工作。 若要解决此问题,包还必须包含以下文件:

ref\net472\MyLib.dll
ref\net472\MyHelpers.dll