visual-studionugetnuget-packagesystem.data.sqlitenuget-spec

How to create my own custom nuget package for System.Data.SQLite to correctly include the interop dlls?


I want to create my own custom package for System.Data.SQLite. I have the all the dll's I need but I'm unsure how to structure it and create the nuspec for it. Current folder structure of the dll's is this, whereabouts would I put the different interop dlls to have them copied correctly to the output and what do I need to add to the nuspec?

lib/net452
  -> System.Data.SQLite.dll , System.Data.SQLite.Linq.dll, System.Data.SQLite.EF6.dll
Custom.SQLite.nuspec

Still have the default nuspec something like this atm

 <?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">
  <metadata minClientVersion="2.5">
    <id>Custom.SQLite.Name</id>
    <version>1.0.0.0</version>
    <authors>name</authors>
    <owners>owner</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Desc</description>
    <copyright>Copyright 2021</copyright>
  </metadata>
</package>

Solution

  • SQLite.Interop.dll does not act as a lib assembly dll. That is not its role. And it should be a content file rather than a assembly dll. So it should not be packed as lib.

    To create such custom nuget package, you should first pack System.Data.SQLite.dll, System.Data.SQLite.Linq.dll, System.Data.SQLite.EF6.dll as lib. See this document.

    and then pack SQLite.Interop.dll as content.

    Also, to make the content file be copied into the output folder of the main project when you install the nuget package, you have to use a <packages_id>.props or targets file to realize it.

    1) create a file called <packages_id>.props into your class library project. And it should be the same name as your nuget package. In your side, it should be named as Custom.SQLite.Name.props. Otherwise, it will not work.

    And then add these into the file:

    <Project>
    
    <ItemGroup>
    <None Include="$(MSBuildThisFileDirectory)..\content\x86\SQLite.Interop.dll">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
            <None Include="$(MSBuildThisFileDirectory)..\content\x64\SQLite.Interop.dll">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    
    </ItemGroup>
    
    </Project>
    

    2) use this nuspec file:

    <?xml version="1.0"?>
    <package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">
      <metadata minClientVersion="2.5">
        <id>Custom.SQLite.Name</id>
        <version>1.0.0.0</version>
        <authors>name</authors>
        <owners>owner</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>Desc</description>
        <copyright>Copyright 2021</copyright>
      </metadata>
    <files>
    <file src="System.Data.SQLite.dll" target="lib\net452" />
    <file src="System.Data.SQLite.EF6.dll" target="lib\net452" />
    <file src="System.Data.SQLite.Linq.dll" target="lib\net452" />
    <file src="xxx\x86\SQLite.Interop.dll" target="content\x86" />
    <file src="xxx\x64\SQLite.Interop.dll" target="content\x64" />
    <file src="Custom.SQLite.Name.props" target="build" />
    
    </files>
    </package>
    

    3) rebuild your lib project and then use nuget pack to pack the new version.

    Before you use this new version, please uninstall the old one and delete all cache files under C:\Users\xxx\.nuget\packages\Custom.SQLite.Name and <solution_folder>\packages\Custom.SQLite.Name.1.0.0. Then, reinstall the new version.