0

I have a Nuget package containing test helper classes that I want to share between solutions. When I try to add the package, I get this message:

install-package : Failed to add reference to 'SQLite.Interop'.

At line:1 char:1

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

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

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

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

My Nuget package has a C# test helper project with references to

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

packages.config contains

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

The .NET project includes

SQLite.Interop.dll as a file

BuildAction: None

Copy to Output Directory: Copy always

SQLite.Interop.dll is included in the Nuget package.

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.

I am using a nuspec file with nuget pack to create the package.

Here is the nuspec file definition:

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

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?

Mike
  • 81
  • 6
  • The SQLLite database is SDF file extension. Do you have a SDF file for the project? – jdweng Feb 02 '18 at 11:42
  • How are you creating Nuget package? Can you share your nuspec file? – Ankit Vijay Feb 02 '18 at 11:56
  • @jdweng I have updated the question to respond to your query – Mike Feb 05 '18 at 15:38
  • @AnkitVijay I have updated the question to respond to your query – Mike Feb 05 '18 at 15:38
  • Check the file Product.wxs. Make sure there are no space at beginning of file. See : https://stackoverflow.com/questions/46340238/program-unable-to-load-dll-sqlite-interop-dll-after-wix-installation – jdweng Feb 05 '18 at 20:23
  • @jdweng There is no .wxs file. – Mike Feb 06 '18 at 14:57
  • dll must be in the bin folder of the VS project.Normally you add a dll to a project by using Add Existing Item and then browse where the dll is located. The when you compile the bin gets automatically copied to the bin folder.The bin folder has a debug and release folders and depending on type of build the dll will automatically get copied.I do not recommend putting the dll manually into bin folder because it can get deleted by the VS compiler (depending on version of VS).The error says fail to add reference. So it may be the folder is wrong.Right click the reference in proj and check path. – jdweng Feb 06 '18 at 17:32
  • @jdweng The .dll is copied to the bin folder. The "Copy to Output Directory": "copy always" achieves this in the source project. A .targets file is used to achieve this in the nuget package. – Mike Feb 07 '18 at 09:07

1 Answers1

0

It turns out that all that was required was a minor change to my nuspec and targets files.

By excluding SQLite.Interop.dll from the .lib directory, Nuget no longer tries to add a reference to the .dll in the target project.

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.

Nuspec file

<?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>
Mike
  • 81
  • 6