繁体   English   中英

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

[英]nuget package add folder to solution

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

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

1)

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

2)

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

...但是似乎没有一个有效!

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

问题是什么? 提前致谢!

罗洛

编辑

nuget规范和项目目录

nuget spec进入nuget包浏览器

我的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>

问题是什么? 提前致谢!

“ Config”文件夹应该出现在项目的根目录而不是解决方案上。

那是因为NuGet团队不赞成 NuGet 3.0中的解决方案级别程序包

因此,应将来自nuget包的内容文件添加到项目中,而不是添加到解决方案中。

此外,根据基于约定的工作目录

在此处输入图片说明

基于约定的工作目录content目录被复制到项目根目录

“ Config”文件夹应出现在项目的根目录下。

在此处输入图片说明

更新:

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

由于您测试的项目类型是.net核心。 您应该使用contentFiles而不是content content用于packages.config。 检查内容文件使用contentFiles元素,并查看博客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包应如下所示:

在此处输入图片说明

注意:创建新程序包时,请不要忘记在C:\\Users\\<UserName>\\.nuget\\packages文件夹中删除该程序包的nuget缓存,否则,它始终会安装旧程序包。

在此处输入图片说明

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM