none
How to include SQLite database with Winforms project and App Center release? RRS feed

  • Question

  • I have a Winforms desktop app written in C# using Visual Studio 2019 and have successfully setup my Azure DevOps pipeline to build and distribute my app to the App Center. The app creates and edits/updates local SQLite database files, but I would like to include a couple of sample databases that already contain valid data so the users can demo the app's other features without having to first create and populate their own databases.

    How can I include these SQLite db files in my release? I'm not seeing a way in Visual Studio to add an SQLite project to my solution, even though I do already have the System.Data.SQLite.Core package installed with my solution.  Based on my searching I've come across terms such as "content files" and "assets" in relation to Visual Studio, but these were from threads that were several years old and I'm not seeing those terms anywhere in Visual Studio 2019.

    Would I be better off just writing code to generate the sample databases with all the sample data and then connecting that code to a GUI menu option? That would also allow the contents of the sample databases to be version controlled, as I'm assuming there's no way to diff an included binary DB against previous versions.

    Wednesday, November 27, 2019 5:46 PM

Answers

  • Here is the solution:

    In Solution Explorer, right click the project name (not the solution name), then click "Add" -> "Existing Item". Navigate to the database (or the file you want to include), then click "Add". Once the file has been added to the project, select it in the Solution Explorer and in the Properties window below, make sure the "Build Action" and "Copy to Output Directory" are set to your preference ("Content" and "Copy if newer" in my case). From that point onward, the files will be included in any release.

    • Marked as answer by hudson4351 Thursday, November 28, 2019 10:19 PM
    Thursday, November 28, 2019 10:19 PM

All replies

  • Typically I would include the database as embedded resource in the app.  The first time the app was run I would copy the database to the apps directory.
    Wednesday, November 27, 2019 6:31 PM
  • Hi hudson4351,

    Welcome to MSDN forum.

    According to your description, I suppose your issue is about the development and our forum is to discuss the VS IDE issues, I will help you move this thread to seek for a better support forum.

    In addition, if you have any more Visual Studio General Questions issues in the future, please feel free to let us know.

    Thanks for your understanding.

    Best Regards,

    Anna


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Thursday, November 28, 2019 6:12 AM
  • Thursday, November 28, 2019 7:28 AM
    Moderator
  • Also try asking for help over here.

    https://social.msdn.microsoft.com/Forums/en-US/home?category=windowsforms

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    Thursday, November 28, 2019 12:11 PM
    Moderator
  • Here is the solution:

    In Solution Explorer, right click the project name (not the solution name), then click "Add" -> "Existing Item". Navigate to the database (or the file you want to include), then click "Add". Once the file has been added to the project, select it in the Solution Explorer and in the Properties window below, make sure the "Build Action" and "Copy to Output Directory" are set to your preference ("Content" and "Copy if newer" in my case). From that point onward, the files will be included in any release.

    • Marked as answer by hudson4351 Thursday, November 28, 2019 10:19 PM
    Thursday, November 28, 2019 10:19 PM