skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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.Databasebin$(Configuration)Stackoverflow.Database.dacpac" Pack="true" PackagePath="OutputDatabase" />
    </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


  2. You can refer Add a readme and other files to use the <files> node in the .nuspec file, which follows the <metadata> tag to add your required database project or DACPAC file to the nuget package.

    Sample .nuspec file:

    <?xml version="1.0"?>
    <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
        <metadata>
        <!-- your properties  -->
        </metadata>
        <files>
            <file src="readme.txt" target="" />
            <file src="pathtoyourDACPAC.dacpac" target="contentDACPAC.dacpac" />
            <file src="....databaseproject***.*" target="databaseproject" />
        </files>
    </package>
    

    Once the NuGet package has been created, you can use it in other projects to access the DACPAC file by installing the NuGet package in your project.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search