Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add sample on how to distribute SQL files from a NuGet package #108

Merged
merged 4 commits into from
Jan 21, 2024

Conversation

MrDave1999
Copy link
Member

@MrDave1999 MrDave1999 commented Jan 21, 2024

Resolves #107

The package was published here: https://www.nuget.org/packages/YeSql.Net.Example.QueryReuse

@MrDave1999
Copy link
Member Author

These instructions to MSBuild do the magic:

  <ItemGroup>
    <Content Include="**\*.sql">
      <Pack>true</Pack>
      <PackagePath>contentFiles\any\$(TargetFramework)\yesql\</PackagePath>
      <PackageCopyToOutput>true</PackageCopyToOutput>
    </Content>
  </ItemGroup>
  • Pack property tells MSBuild to include the content (SQL files) to the nuget package.
  • PackagePath property is to specify the path where the SQL files will be copied to the nuget package.
    SQL files must be copied to this path: contentFiles\any\$(TargetFramework). $(TargetFramework) macro is expanded in this case to "netstandard2.0".
    See documentation: https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#including-content-in-a-package
  • PackageCopyToOutput property will tell MSBuild to copy the SQL files to the output directory of the project that references the nuget package.

When the package is created with the "dotnet pack" command, the .nuspec file must contain the following:

<contentFiles>
   <files include="any/netstandard2.0/yesql/Receipts/receipt.sql" buildAction="Content" copyToOutput="true" />
   <files include="any/netstandard2.0/yesql/Receipts/receiptDetails.sql" buildAction="Content" copyToOutput="true"  />
</contentFiles>

Obviously this is just an example but the .nuspec file should contain the files that should be copied to the output directory of the project that references the nuget package.

@MrDave1999 MrDave1999 marked this pull request as ready for review January 21, 2024 17:12
@MrDave1999 MrDave1999 merged commit d639f36 into master Jan 21, 2024
1 check passed
@MrDave1999 MrDave1999 deleted the docs/issue-107 branch January 21, 2024 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add sample on how to distribute SQL files from a NuGet package
1 participant