I have a nuget package containing my SQL database project. How can I reference the dacpac file in the package in order to deploy it to my azure sql server? I would like to do this from my ASP.net core application.
-
Can you explain more about what you’re doing? Are you trying to deploy the database when you install the package? Or read from the package after installation? When you say ‘database project’ is that an SSDT project? Why is your database project in a package anyway, are you planning on distributing it? – stuartd Mar 26 '20 at 22:08
-
The ASP.net core application is actually a container running in azure. The idea is to create a database for the customer when they're on-boarded. By calling an API endpoint the database is deployed. – user3688401 Mar 26 '20 at 23:34
-
So where the DB is deployed is up to the customer? What’s the workflow here? – stuartd Mar 27 '20 at 00:16
-
try to explain more. what are you going to do – Udara Kasun Mar 27 '20 at 03:38
-
SQL Elastic Pool is where customer databases would be deployed. So, the where is not optional. During customer on-boarding the endpoint is called to trigger creating the db. Each customer must have their own database in the pool. In essence, i'm looking to automate db creation and the deployment of schema when triggered by the API endpoint. – user3688401 Mar 27 '20 at 15:33
-
Is there a way to get a data file copied to the build folder similar to a dll from the same nuget package? – user3688401 Apr 01 '20 at 15:51
1 Answers
I needed to do this too, so here is what worked for me:
If your application uses the new SDK format, you can reference content files in a referenced nuget package in your project. You need to add the <GeneratePathProperty>
node with a value of true in the package reference:
<ItemGroup>
<PackageReference Include="My.Package" Version="1.0.1">
<GeneratePathProperty>true</GeneratePathProperty>
</PackageReference>
</ItemGroup>
Then you can include the file you want to reference using a content link. The VS variable name is by convention starting with the prefix "Pkg" and replacing periods with underscores. You can also optionally include a <Link>
node which provides a "notional" path for the included file when viewing it in your project. Example below:
<ItemGroup>
<Content Include="$(PkgMy_Package)\contentFiles\any\net48\SomeDb.dacpac">
<Link>dacpac\SomeDb.dacpac</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>true</Pack>
</Content>
</ItemGroup>
The content file will be copied to the build output folder during build just like any other content file.
This is supported from VS 2017 15.9. Credit to Georg Dangl from his blog post: https://blog.dangl.me/archive/accessing-nuget-package-paths-in-your-net-sdk-based-csproj-files/

- 111
- 1
- 7