nuget package add folder to solution

2019-08-30 18:31发布

问题:

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>

回答1:

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:

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

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

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:

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.

Hope this helps.