首页 文章

nuget包添加文件夹到解决方案

提问于
浏览
0

我必须创建一个nuget包但我有一个问题:我想添加一个名为“Config”的文件夹,这个文件夹包含三个XML文件 .

在网上搜索后,我尝试了两种方法(编辑我的nuspec文件)将这个自定义文件夹添加到我的nuget包中:

1)

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

2)

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

......但这些似乎没有人工作!

我试图在Test的解决方案(控制台应用程序)上添加此软件包,dll已附加到解决方案,但“Config”文件夹未出现在解决方案的根目录中 .

问题是什么?提前致谢!

Lollo

EDIT

nuget spec and project directory

nuget spec opened into nuget package explorer

我的Nuget规范文件:

<?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 回答

  • 2

    问题是什么?提前致谢!

    "Config"文件夹应出现在 project 的根目录而不是解决方案上 .

    那是因为NuGet团队deprecated solution level packages在NuGet 3.0中 .

    所以来自nuget包的内容文件应该添加到项目中,而不是解决方案 .

    另外,根据From a convention-based working directory

    enter image description here

    基于约定的工作目录 contentContents are copied to the project root .

    “Config”文件夹应出现在项目的根目录中 .

    enter image description here

    Update:

    我已根据您的要求编辑了我的问题:)我正在使用.NET核心2.0

    由于您测试项目类型是.net核心 . 您应该使用 contentFiles 而不是 content . content 用于packages.config . 有关详细信息,请查看Using the contentFiles element for content files和博客NuGet ContentFiles Demystified .

    所以你的 .nuspec 文件应该是:

    <?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>
    

    nuget包应该看起来像:

    enter image description here

    Note: 创建新包时,不要忘记在 C:\Users\<UserName>\.nuget\packages 文件夹中删除此包的nuget缓存,否则,它始终安装旧包 .

    enter image description here

    希望这可以帮助 .

相关问题