如何在我的新CSPROJ类库中包含带有本机dll的NuGet包?

问题描述 投票:2回答:1

我有一个类库,我刚刚迁移到新的csproj格式,它依赖于SQLite.Core

SQLite有本机依赖项x64/SQLite.Interop.dllx86/SQLite.Interoop.dll,它曾经被复制到输出文件夹中,用于添加我的包的任何项目。这由NuGet通过在旧的csproj文件中自动包含以下导入来处理:

<Import Project="..\packages\System.Data.SQLite.Core.1.0.106\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.106\build\net451\System.Data.SQLite.Core.targets')" />

迁移到新的csproj之后,我可以将我的库构建为一个NuGet包,它正确地包含SQLite.Core作为依赖项,但是任何使用我的NuGet库的人都不会获得输出文件夹的本机依赖项。

另一方面,如果消费者首先添加SQLite.Core然后添加我的包一切正常。

知道如何在迁移之前恢复行为吗?以下是迁移的csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <PackageId>My.Library</PackageId>
    <Description>Some Library.</Description>        
  </PropertyGroup>

  <PropertyGroup>
    <TargetFramework>net452</TargetFramework>    
    <AssemblyName>My Library</AssemblyName>    
  </PropertyGroup>

  <ItemGroup>    
    <PackageReference Include="System.Data.SQLite.Core" Version="1.0.106" />
  </ItemGroup>

    <ItemGroup>
      <Reference Include="Microsoft.CSharp" />
    </ItemGroup>    

</Project>
c# .net msbuild nuget csproj
1个回答
2
投票

由于System.Data.SQLite.Core使用构建时逻辑将包包含到内容中,因此如果构建引用该包的库,则PackageReference的默认依赖项设置不适合。默认情况下,PackageReference不会转发contentFiles,构建资产和分析器以进行传递引用。

要更改该行为,请将您的PackageReference编辑为:

<PackageReference Include="System.Data.SQLite.Core" Version="1.0.106" PrivateAssets="none"/>

这将确保在通过库直接或传递引用时包的行为完全相同。在你的具体情况下,PrivateAssets也可能是contentFiles;analyzers,因为只需要转发build,但由于该软件包只包含build资产,因此无关紧要。

有关详细信息,请参阅Controlling dependency assets

© www.soinside.com 2019 - 2024. All rights reserved.