Search code examples
c#wpfinstallationlocaldb

Create c# app setup with database project


So basically I want to have an installer for my WPF application. In the setup process I want to automatically create a localdb. For this I already have a database project in the solution that contains all the tables for my database. I was already able to manage to have an installer for the application itself. For this I used the "Microsoft Visual Studio 2015 Installer Projects" addon in VS 2015. My questions:

  1. How can I automatically create a localdb instance in the setup process?

  2. How can I use the database project to automatically create the database?

  3. Is there a better solution to create setup file, than the mentioned?


Solution

  • You can build the .dacpac file in the Database project, include the dacpac in the WPF app as embedded resource, and use the DacFX SDK to install/update the database based on a connection string.

    Code sample: https://github.com/ErikEJ/SqlCeToolbox/blob/issue-357-a/src/GUI/SqlCe35Toolbox/Helpers/DacFxHelper.cs

    DacFX is available as a NuGet package now:

    https://www.nuget.org/packages/Microsoft.SqlServer.DacFx.x64/ or https://www.nuget.org/packages/Microsoft.SqlServer.DacFx.x86/