nuget包将文件夹添加到解决方案 [英] nuget package add folder to solution

查看:212
本文介绍了nuget包将文件夹添加到解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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!

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

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!

哈罗

编辑

获取规范和项目目录

在nuget包资源管理器中打开了nuget规范

我的Nuget规范文件:

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>

推荐答案

出什么问题了?预先感谢!

What is the problem? Thanks in advance!

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

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

那是因为NuGet团队在NuGet 3.0中已弃用的解决方案级别软件包.

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

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

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

此外,根据基于常规工作目录:

基于约定的工作目录content内容已复制到项目根目录.

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

"Config"文件夹应该出现在项目的根目录上.

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

更新:

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

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

由于您测试的项目类型是.net核心.您应该使用contentFiles而不是content. content用于packages.config.检查使用内容文件的contentFiles元素和博客 NuGet解密内容文件有关更多详细信息.

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.

因此,您的.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包应如下所示:

The nuget package should be looks like:

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

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.

希望这会有所帮助.

这篇关于nuget包将文件夹添加到解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆