简体   繁体   English

如何将SQLite.Interop.dll添加到Nuget包中,这样不会出现“无法添加引用”错误?

[英]How do I add SQLite.Interop.dll to a Nuget package so I don't get a 'Failed to add reference' error?

I have a Nuget package containing test helper classes that I want to share between solutions. 我有一个Nuget软件包,其中包含要在解决方案之间共享的测试帮助程序类。 When I try to add the package, I get this message: 当我尝试添加软件包时,收到以下消息:

install-package : Failed to add reference to 'SQLite.Interop'. install-package:无法添加对“ SQLite.Interop”的引用。

At line:1 char:1 在第1行:char:1

+ install-package 'c:\\work\\directory_name\\package_name.nu ... +安装软件包'c:\\ work \\ directory_name \\ package_name.nu ...

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

+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception + CategoryInfo:未指定:(:) [Install-Package],异常

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

My Nuget package has a C# test helper project with references to 我的Nuget软件包有一个C#测试帮助程序项目,其中包含对

  • System.Data 系统数据
  • System.Data.DataSetExtensions System.Data.DataSetExtensions
  • System.Data.SQLite System.Data.SQLite

packages.config contains packages.config包含

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

The .NET project includes .NET项目包括

SQLite.Interop.dll as a file SQLite.Interop.dll作为文件

BuildAction: None BuildAction:无

Copy to Output Directory: Copy always 复制到输出目录:始终复制

SQLite.Interop.dll is included in the Nuget package. SQLite.Interop.dll包含在Nuget包中。

It goes without saying that there are no references to SQLite.Interop in either the test helper project (which is in the Nuget package) or the project I am trying to add the Nuget package to. 不用说,在测试帮助程序项目(位于Nuget包中)或我尝试向其中添加Nuget包的项目中都没有对SQLite.Interop的引用。

I am using a nuspec file with nuget pack to create the package. 我正在使用带有nuget pack的nuspec文件来创建包。

Here is the nuspec file definition: 这是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>

There is no .sdf file in the project 项目中没有.sdf文件

Any ideas on how to set up this Nuget package, so I can add it to other projects and have SQLite.Interop.dll copied into their output directories? 关于如何设置此Nuget包的任何想法,这样我就可以将其添加到其他项目中,并将SQLite.Interop.dll复制到其输出目录中?

It turns out that all that was required was a minor change to my nuspec and targets files. 事实证明,所需要做的只是对我的nuspec和target文件进行了微小的更改。

By excluding SQLite.Interop.dll from the .lib directory, Nuget no longer tries to add a reference to the .dll in the target project. 通过从.lib目录中排除SQLite.Interop.dll,Nuget不再尝试在目标项目中添加对.dll的引用。

I can still include the interop dll by putting it in the .content directory and then use the .targets file to include it in the target project. 我仍然可以通过将interop dll放在.content目录中,然后使用.targets文件将其包含在目标项目中来包括它。

Nuspec file 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>

Targets file 目标文件

<?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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM