Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
931 views
in Technique[技术] by (71.8m points)

.net - nuget package add folder to solution

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="contentConfig" />

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="binRelease
etcoreapp2.0*.dll" target="lib
etcoreapp2.0" />
        <file src="binRelease
etcoreapp2.0*.pdb" target="lib
etcoreapp2.0" />

        <file src="Config*.*" target="contentConfig" />
    </files>
</package>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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="binRelease
etcoreapp2.0*.dll" target="lib
etcoreapp2.0" />
        <file src="binRelease
etcoreapp2.0*.pdb" target="lib
etcoreapp2.0" />
        <file src="contentFilesanyanyConfig*.*" target="contentFilesanyanyConfig" />
  </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>.nugetpackages folder, otherwise, it always install the old package.

enter image description here

Hope this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...