我想你对这部分有一些误解。
首先,contentFiles适用于具有PackageReference nuget 管理格式Net Core
的 new-sdk 项目(和Net Standard
),而不是具有packages.config nuget 管理格式的项目。Net Framework
并且contentFiles
适用于内容文件而不是 lib 文件夹。所以你不应该将这些 dll 文件打包到target="lib\any\any\.....dll"
. 您应该将它们打包到contentFiles
文件夹中。
用这个:
<contentFiles>
<files include="any/any/*" buildAction="Content" copyToOutput="true" flatten="true" />
</contentFiles>
<files>
<file src="xxx\First.dll(the physical, relative path of the dll on your project folder)" target="contentFiles\any\any\First.dll"></file>
<file src="xxx\Second.dll(the physical, relative path of the dll on your project folder)" target="contentFiles\any\any\Second.dll"></file>
<file src="xxx\....dll(the physical, relative path of the dll on your project folder)" target="contntFiles\any\any\.....dll"></file>
<files>
然后,您应该在Net Core项目上安装这个 nuget 包。
完成后,使用nuget pack
命令重新打包项目,然后,在安装新项目之前,先清理 nuget 缓存以删除旧版本。然后,在一个Net Core项目上安装新版本,可以看到如下效果:

==================================================== =====================
如果您仍想在Net Framework
项目中使用此功能,则应将这些文件打包在content
node 上而不是contentFiles
.
你只需要添加两行:
<contentFiles>
<files include="any/any/*" buildAction="Content" copyToOutput="true" flatten="true" />
</contentFiles>
<files>
<file src="xxx\First.dll(the physical, relative path of the dll on your project folder)" target="contentFiles\any\any\First.dll"></file>
<file src="xxx\Second.dll(the physical, relative path of the dll on your project folder)" target="contentFiles\any\any\Second.dll"></file>
<file src="xxx\....dll(the physical, relative path of the dll on your project folder)" target="contntFiles\any\any\.....dll"></file>
<file src="xxx\First.dll(the physical, relative path of the dll on your project folder)" target="content"></file>
<file src="xxx\Second.dll(the physical, relative path of the dll on your project folder)" target="content"></file>
..........
<files>
但是这些根本无法改变导入文件的属性。而对于 net framework 项目,更改文件的属性不能在xxx.nuspec
文件上完成。
您应该使用<packages_id>.props 或目标文件。
1)在解决方案资源管理器<packages_id>.props
的 build 文件夹下创建一个名为的文件,如果您的 nuget 包命名为,则应将其命名为 ,以便它可以工作。ThisProject.1.0.0.nupkg
ThisProject.props
这是我的:

2)在道具文件中添加这些:
<Project>
<ItemGroup>
<Content Include="First.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Second.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
......
</ItemGroup>
</Project>
3)在文件中添加一行nuspec
以将道具文件包含到nupkg中。
<file src="build\xxx.props(the physical, relative path of the file on your project folder)" target="build"></file>
4)然后重新打包 nuget 包,清理 nuget 缓存,然后在 Net Framework 项目上安装这个新的packages.config
.
注意:虽然解决方案资源管理器上导入的内容文件的属性窗口没有显示更改的值,并且仍然显示旧值,但文件已经复制到项目的输出文件夹中。这是解决方案资源管理器上的 UI 显示问题,更改的值已被使用并且运行良好。所以你不必太在意。