0

i have to create a nuget package but i have a problem: i want to add a folder named "Config", this folder contains three XML files.

after a search on the web, i have tried two ways (editing my nuspec file) to add this custom folder into my nuget package:

1)

<file src="Config\*.*" target="content\Config" />

2)

<file src="Config\*.*" target="Config" />

... but no one of these seem to work!

I have tried to add this package on a Test's solution (Console application), the dll was attached to the solution but "Config" folder doesn't appeared on the root of the solution.

What is the problem? Thanks in advance!

Lollo

EDIT

nuget spec and project directory

nuget spec opened into nuget package explorer

My Nuget Specification file:

<?xml version="1.0"?>
<package  xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
    <metadata>    
        <id>Onions.Framework.Core</id>
        <version>1.0.0</version>
        <title>Onions Framework Core</title>
        <authors>Onions Corporate</authors>
        <owners>Onions Corporate</owners>
        <licenseUrl>http://url/framework/core/license.txt</licenseUrl>
        <projectUrl>http://url/framework/core/</projectUrl>
        <iconUrl>http://url/framework/icon.png</iconUrl>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>no description</description>
        <releaseNotes></releaseNotes>
        <copyright>Onions Corporate</copyright>
        <tags></tags>
        <dependencies>
              <dependency id="Castle.Core" version="4.2.1" />
              <dependency id="Castle.Windsor" version="4.1.0" />
              <dependency id="CommonServiceLocator" version="2.0.1" />
              <dependency id="FluentNHibernate" version="2.0.3" />
              <dependency id="Iesi.Collections" version="4.0.3" />
              <dependency id="log4net" version="2.0.8" />
              <dependency id="Newtonsoft.Json" version="10.0.3" />
              <dependency id="NHibernate" version="4.1.1.4000" />
        </dependencies>
        <summary></summary>
    </metadata>
    <files>
        <file src="bin\Release\netcoreapp2.0\*.dll" target="lib\netcoreapp2.0" />
        <file src="bin\Release\netcoreapp2.0\*.pdb" target="lib\netcoreapp2.0" />

        <file src="Config\*.*" target="content\Config" />
    </files>
</package>
Lollo
  • 535
  • 2
  • 5
  • 18

1 Answers1

4

What is the problem? Thanks in advance!

The "Config" folder should appeared on the root of the project rather than solution.

That because NuGet team deprecated solution level packages in NuGet 3.0.

So the content files comes from nuget package should be added to the project, not the solution.

Besides, according the From a convention-based working directory:

enter image description here

The convention-based working directory content, Contents are copied to the project root.

The "Config" folder should appeared on the root of the project.

enter image description here

Update:

i have edited my question with your requests :) i'm using .NET core 2.0

Since you test project type is .net core. You should use contentFiles instead of content. content is used for packages.config. Check the Using the contentFiles element for content files and blog NuGet ContentFiles Demystified for more details.

So your .nuspec file should be:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>Onions.Framework.Core</id>
    ...

    <contentFiles>
      <files include="any/any/Config/*.*" buildAction="Content" copyToOutput="false" flatten="true" />
    </contentFiles>

  </metadata>

  <files>
        <file src="bin\Release\netcoreapp2.0\*.dll" target="lib\netcoreapp2.0" />
        <file src="bin\Release\netcoreapp2.0\*.pdb" target="lib\netcoreapp2.0" />
        <file src="contentFiles\any\any\Config\*.*" target="contentFiles\any\any\Config" />
  </files>
</package>

The nuget package should be looks like:

enter image description here

Note: When you create a new package, do not forgot to remove the nuget cache for this package in the C:\Users\<UserName>\.nuget\packages folder, otherwise, it always install the old package.

enter image description here

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • sorry, i would mean "project" instead "solution". but i cannot import the "Config" folder to my project using nuget :( even if the dll and pdb files are imported successfully... – Lollo Apr 16 '18 at 08:03
  • @Lollo, so you means your "Config" folder doesn't appeared on the root of the project? If yes, could you please share your .nuspec file to me or your nuget package to me, if you do not mind. And what is your project type of your Console application, .net framework or .net core? – Leo Liu Apr 16 '18 at 08:18
  • i have edited my question with your requests :) i'm using .NET core 2.0 – Lollo Apr 16 '18 at 08:43
  • @Lollo, Since you test project type is .net core. You should use `contentFiles` instead of `content`. `content` is used for packages.config. Check my update answer for details. – Leo Liu Apr 16 '18 at 09:19
  • @Lollo, I have uploaded the error `.nuspec` file, please change it to``, I have updated the answer, you can check it. I have test it with a .net core app. – Leo Liu Apr 17 '18 at 02:41
  • Why `any/any/...` ? – huang Nov 28 '20 at 01:05