asp.netazure-devopsnugetsqlproj

NuGet Package Including DACPAC SQLProj


The goal is to build a NuGet Package, that also depends on an SQLProj that will produce a DACPAC file.

So when building the project that is using this NuGet Package, the goal is to access the DACPAC file when releasing the application in the Azure Pipeline Release:

The Application depends on this NuGet Package but also needs to pack the database project with that package to be able to access the DACPAC file included in the Nuget during the release of the application


Solution

  • the simplest way is to reference the dacpac database file directly in the csproj from the bin folder like this :

    <!-- Include the DACPAC file from the Database project -->
    <ItemGroup>
        <None Include="..\Stackoverflow.Database\bin\$(Configuration)\Stackoverflow.Database.dacpac" Pack="true" PackagePath="Output\Database\" />
    </ItemGroup>
    

    Just make sure the you build the database project before building the csproj for exemple if you're packaging and publishing your package from an Azure Pipeline

    Then build the database project:

    msbuild Stackoverflow.Database.sqlproj /p:Configuration=Release
    

    And build the cs project:

    msbuild Stackoverflow.csproj /p:Configuration=Release
    

    And finally pack the library: dotnet pack --configuration Release