Deploying DacPac/BacPac to SqlServer during startup #5530
egil
started this conversation in
Show and tell
Replies: 2 comments 3 replies
-
Have you tried https://www.nuget.org/packages/MSBuild.Sdk.SqlProj.Aspire/8.1.0-preview-0006-gf03438655c ? |
Beta Was this translation helpful? Give feedback.
1 reply
-
You should always just use publish and it will create the database if it does not exist. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This is how I managed to get Aspire to spin up a SqlServer and deploy a DacPac/BacPac to the server to set up databases.
To get DacPac building working on Linux, I followed @ErikEJ's guide to set up Visual Studio Sql Server project and a companion netstandard build project, and then, I customized the sqlserver docker image to include dotnet sdk.
This is my solution structure:
Content of
/src/AppHost/sqlserverconfig/Docker
(remember to save withLF
line endings):Content of
/src/AppHost/sqlserverconfig/entrypoint.sh
(remember to save withLF
line endings):Content of
/src/AppHost/sqlserverconfig/configure-db.sh
(remember to save withLF
line endings):Remember to change the
MY_DATABASE_NAME
variable to the name of your database!As you can see, the scripts offer to import a
bacpac
that is present in the/src/AppHost/sql-data
folder if it finds one. Otherwise, it will build a dacpac from the database project and publish that to the server.The startup time will be slow the first time, but because we are using data volumnes and checking if the database exists, the start up time will be short after the first time it has run.
NOTE: I am by no means a SQL or Aspire expert. Any suggestions for improvements are very welcome!
Beta Was this translation helpful? Give feedback.
All reactions