Kyle J V
Kyle J V

Reputation: 603

How do I include a non-dll file from build output (dacpac) in a dotnet pack nuget package?

I currently have a .NET Standard 2.0 library that is a repository against a sql database. I also have a .sqlproj project in the same solution for that particular database. The repository library gets built, packed, and pushed to our nuget repository from our build server (Azure DevOps) using the dotnet pack command on 2.2 cli. I would like to include the dacpac from the database project as part of the repository nuget package so that releases from consumers of that package can deploy the dacpac changes. I plan on making sure that the version being overwritten is later than the package version on deployment.

I am able to add the dacpac file to the build output of the repository project by using a before build target

<Target Name="mydb" AfterTargets="Build"> <Exec Command="XCOPY /Y /R ..\db\bin\$(ConfigurationName)\mydb.dacpac $(TargetDir)" /> </Target>

My current issue is that although the file copies, it is not included in the resulting nuget file from dotnet pack repository.csproj

Upvotes: 2

Views: 399

Answers (1)

Kyle J V
Kyle J V

Reputation: 603

I found the answer in the depths of MS documentation: In addition to the target, I needed to add a Content to include the file that I just copied.

<ItemGroup>
    <Content Include="$(TargetDir)\mydb.dacpac" >
      <Pack>true</Pack>
      <PackagePath>\dacpacs\</PackagePath>
    </Content>
  </ItemGroup>  

https://learn.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-visual-studio?tabs=netcore-cli

Upvotes: 2

Related Questions