问题描述
在将 .NET 项目编译成 NUGET 包时,如果项目引用了其它 dll 文件,则可能出现这个警告,如果不处理,Nuget 包中可能无法正确引用所添加的 dll 。
处理方式
在项目 .csproj 文件中添加如下内容:
<ItemGroup> <Content Include="lib\*.dll"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <PackagePath>.\lib\net45</PackagePath> </Content> </ItemGroup>
<Content Include="lib\*.dll">
中的 lib
是项目中自定义的文件夹,这里的意思就是,将项目中 lib 文件夹下所有的 dll 文件,在生成时,其 PackagePath
都设置到 Nuget 包中的 `.\lib\net45 目录下。
net45
指这个项目的编译目标框架 ,最终,将在 Nuget 包的输出目录中,得到项目生成的 dll 和所引用的 dll 。
其它属性:
Common MSBuild Project Items - Visual Studio | Microsoft Docs
参考链接
- NuGet Warning NU5100 | Microsoft Docs
- docs.microsoft.com-nuget/NU5100.md at master · NuGet/docs.microsoft.com-nuget
- Nupkg Containing Native Libraries - DEV Community
原文链接: https://blog.jgrass.cc/posts/nuget-warning-nu5100/
本作品采用 「署名 4.0 国际」 许可协议进行许可,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。