使用csproj

时间:2018-07-06 21:28:44

标签: .net-core nuget

我正在开发一个依赖于非托管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.

I know that I can embed the unmanaged DLLs by writing a .nuspec(实际上,我有)。但是,似乎不需要用最新的.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。

1 个答案:

答案 0 :(得分:6)

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

<ItemGroup>
  <None Include="unmanaged.dll" Pack="true" PackagePath="runtimes\win-x64\native" />
</ItemGroup>