.net-core - 使用csproj在NuGet程序包中包含非托管DLL

标签 .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。

    最佳答案

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

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

    关于.net-core - 使用csproj在NuGet程序包中包含非托管DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51217832/

    相关文章:

    azure - 无法在 Azure 应用服务上启动 Kestrel 抛出无法配置 HTTPS 端点异常

    c# - dotnet 核心数据库首先使用 NetTopologySuite

    c# - 使用不同域中的 oidc-client 和 identityServer4 登录

    msbuild - 如何设置TeamCity以使用自己的HTTP身份验证的NuGet服务?

    visual-c++ - 如何让 MSBuild 自动下载解决方案/项目中引用的新 nuget 包?

    asp.net - 点网核心 : Object reference not set to an instance of an object

    .net-core - Blazor 路由在同一页面中更改

    c# - 如何在 visual studio 项目模板中添加引用和 nugets?

    asp.net-mvc - MVCScaffoliding 包抛出 MethodInvocationException

    c# - 如何通过 NuGet 为 resharper 下载 respeller?