How can I make my C# app actually deploy with a copy of its SQLite database?


I am working on a C# app which uses a SQLite database.

I have a connection string indicated in app.config which uses a relative path to target the database file.

The target relative to the project root is ./Data/MyDb.db

However, 2 things can happen based on my publish properties with VS publish menu:

Option 1:

In Project > Properties > Publish > Application Files, if I mark the publish status of /data.MyDb.db to "Include", when deploying the app, I have no idea where the database file is located. It does save and retrieve data successfully within the app, but I haven’t got a clue of where these changes are being written, because the file in the installation folder /Data/MyDb.db.deploy is not storing them. I can add a new record and no modification is made to the file, but the app is still capable of retrieving the record, even after rebooting the pc, meaning that it is indeed saving the data somewhere.

Option 2:

if I mark the data/MyDb.db file publish status to "Data File" instead, when I deploy the app and write data in it, all of the data is stored in the SAME file that is in the folder of the development project. The deployment DOES NOT copy the file to its installation folder. This might not seem so inconvenient since at least I know where the changes are being written, but it seems cumbersome because I’d need to drag around the project folder wherever I want to install the application, when it should be completely independent.

Is there a way to either have the project actually copy the DB file into the installation folder or at least to determine where the live app is storing the changes? Or is there something I’m missing? Any better way to integrate the database?

Source: Visual Studio Questions