GithubHelp home page GithubHelp logo

matjazbravc / embedded-sqlite-demo Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 1.37 MB

Costura.Fody is an add-in for Fody and it is by far the best and easiest way to embed external assemblies in your executable.

C# 100.00%
sqlite sqlite-database embedded costura-fody fody csharp csharp-code

embedded-sqlite-demo's Introduction

Embedding SQLite in Console Application Demo

Costura.Fody is an add-in for Fody and it is by far the best and easiest way to embed external assemblies in your executable.

It is just enough to add Costura NuGet Package to your project and all of the external libraries will automatically be embedded into your executable after build!

In our case external library SQLite.Interop.dll targeting both platforms, 32 and 64-bits and we have to embed both dlls. That's why we have to create two folders called costura32 and costura64 and copy the correct version of SQLite.Interop.dll into each one. We also have to change the Build Action for both files to Embedded Resource.

By installing Costura NuGet Package a config file called FodyWeavers.xml was added to the root folder of project. Usually you don’t have to specify what external libraries to embed, but for all external libraries that are targeted to a specific platform (32 and 64-bits) we have to specify this in the FodyWeavers.xml like it is in our case (do not include .dll in the names):

<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
  <Costura IncludeDebugSymbols='false'>
    <Unmanaged32Assemblies>
      SQLite.Interop
    </Unmanaged32Assemblies>
    <Unmanaged64Assemblies>
      SQLite.Interop
    </Unmanaged64Assemblies>
  </Costura>
</Weavers>

It is also important that you set IncludeDebugSymbols='false' which exclude .pdbs for referenced assemblies to be embedded.

You will notice that after rebuild your project is quite larger then it was before. Now you can move your executable outside debug directory and run it without breaking any dependencies.

Prerequisites:

Enjoy!

Licence

Licenced under MIT. Contact me on LinkedIn.

embedded-sqlite-demo's People

Contributors

matjazbravc avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

xiaofghd893

embedded-sqlite-demo's Issues

Can you make an Embedded-LevelDB-Demo?

Can you make an Embedded-LevelDB-Demo?

PM> Install-Package LevelDB.Standard

test Code

  • System.TypeInitializationException:““LevelDB.LevelDBInterop”
using System;
using System.IO;

namespace EmbeddedSQLiteDemo
{
    internal class Program
    {
   
        private static void Main()
        {
            var options = new LevelDB.Options { CreateIfMissing = true };

            Console.WriteLine();
            Console.WriteLine("Press <Enter> key to exit.");
            Console.ReadLine();
        }
    }
}

i have try it but i failed

  • FodyWeavers.xml
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
	<Costura IncludeDebugSymbols='false'>
		<Unmanaged32Assemblies>
			leveldb
		</Unmanaged32Assemblies>
		<Unmanaged64Assemblies>
			leveldb
		</Unmanaged64Assemblies>
	</Costura>
</Weavers>

thanks very much

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.