【问题标题】:How do I add SQLite.Interop.dll to a Nuget package so I don't get a 'Failed to add reference' error?如何将 SQLite.Interop.dll 添加到 Nuget 包中,以免出现“添加引用失败”错误?
【发布时间】:2018-07-12 19:34:56
【问题描述】:

我有一个 Nuget 包,其中包含我想在解决方案之间共享的测试助手类。当我尝试添加包时,我收到以下消息:

安装包:未能添加对“SQLite.Interop”的引用。

在 line:1 char:1

+ install-package 'c:\work\directory_name\package_name.nu ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception

+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

我的 Nuget 包有一个 C# 测试助手项目,其中引用了

  • System.Data
  • System.Data.DataSetExtensions
  • System.Data.SQLite

packages.config 包含

<package id="System.Data.SQLite" version="1.0.65" targetFramework="net451" />

.NET 项目包括

SQLite.Interop.dll 作为文件

BuildAction:无

复制到输出目录:始终复制

SQLite.Interop.dll 包含在 Nuget 包中。

不用说,在测试助手项目(位于 Nuget 包中)或我尝试将 Nuget 包添加到的项目中都没有对 SQLite.Interop 的引用。

我正在使用带有 nuget pack 的 nuspec 文件来创建包。

这里是 nuspec 文件定义:

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
  <metadata>
    <id>...</id>
    <version>1.0.0</version>
    <title>...</title>
    <authors>...</authors>
    <owners>..</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>...</description>
    <copyright>...</copyright>
    <releaseNotes>
    </releaseNotes>
  </metadata>
  <files>
    <file src="build\bin\**" target="lib\net45" />
    <file src="package_name.targets" target="build"/>
  </files>
</package>

项目中没有.sdf文件

关于如何设置这个 Nuget 包的任何想法,以便我可以将它添加到其他项目并将 SQLite.Interop.dll 复制到它们的输出目录中?

【问题讨论】:

  • SQLLite 数据库是 SDF 文件扩展名。你有项目的 SDF 文件吗?
  • 你是如何创建 Nuget 包的?你能分享你的 nuspec 文件吗?
  • @jdweng 我已更新问题以回复您的查询
  • @AnkitVijay 我已更新问题以回复您的查询
  • 检查文件 Product.wxs。确保文件开头没有空格。请参阅:stackoverflow.com/questions/46340238/…

标签: c# sqlite nuget interop


【解决方案1】:

事实证明,我所需要的只是对我的 nuspec 和目标文件进行微小更改。

通过从 .lib 目录中排除 SQLite.Interop.dll,Nuget 不再尝试在目标项目中添加对 .dll 的引用。

我仍然可以通过将互操作 dll 放在 .content 目录中来包含它,然后使用 .targets 文件将其包含在目标项目中。

Nuspec 文件

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
  <metadata>
    <id>...</id>
    <version>1.0.0</version>
    <title>...</title>
    <authors>...</authors>
    <owners>..</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>...</description>
    <copyright>...</copyright>
    <releaseNotes>
    </releaseNotes>
  </metadata>
  <files>
    <file src="build\bin\**" target="lib\net45" exclude="build\bin\SQLite.Interop.dll" />
    <file src="build\bin\SQLite.Interop.dll" target="content"/>
    <file src="package_name.targets" target="build"/>
  </files>
</package>

目标文件

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <None Include="$(MSBuildThisFileDirectory)\..\content\SQLite.Interop.dll">
      <Link>SQLite.Interop.dll</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

【讨论】:

  • targets和nuspec文件在哪里?
猜你喜欢
  • 2018-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多