Home > OS >  Why are the files from the contentFiles folder not getting copied over to the bin folder?
Why are the files from the contentFiles folder not getting copied over to the bin folder?

Time:05-23

I'm trying to get my sql files from the nuget package to the bin folder of my Application. I was setting up the .nuspec file for it. I can see in the .nuget folder that the sql files are a part of the nuget package but they are not reflected in the bin/Debug folder.

<?xml version="1.0" encoding="utf-8"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>Athi</authors>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
    <copyright>$copyright$</copyright>
    <tags>Logger</tags>
    <dependencies>
        <dependency id="Dapper" version="2.0.123" />
        <dependency id="System.Data.SqlClient" version="4.8.3" />
    </dependencies>
      <contentFiles>
          <files include="bin\Release\net6.0\Scripts\*.sql" buildAction="Content" copyToOutput="true" />
      </contentFiles>
  </metadata>
  <files>
      <file src="bin\Release\net6.0\Scripts\*.*" target="lib\net6.0\Scripts" />
      <file src="bin\Release\net6.0\Scripts\*.*" target="contentFiles\Scripts" />
  </files>
</package>

CodePudding user response:

Firstly, according to the docs:

The package project should structure content using the following pattern:

/contentFiles/{codeLanguage}/{TxM}/{any?}

For example:

Language- and framework-agnostic:
    /contentFiles/any/any/config.xml

net45 content for all languages
    /contentFiles/any/net45/config.xml

C#-specific content for net45 and up
    /contentFiles/cs/net45/sample.cs

It doesn't look like you are putting them into the correct directory in your NuGet package.

Secondly, according to the docs, contentFiles is only supported on NuGet 4.0 with PackageReference. Are you using a high enough version of NuGet? Are you using PackageReference in your project files instead of a packages.config file in your project?

TIP: If you find the documentation is lacking in examples of what you are attempting to do, download some (recently made) real packages from https://nuget.org to locate one that does something similar to what you want and use NuGet Package Explorer to see how the packages are arranged.

  • Related