【问题标题】:Include content files in nuget package using project.json使用 project.json 在 nuget 包中包含内容文件
【发布时间】:2017-01-25 18:29:03
【问题描述】:

我正在使用这个 .nuspec 文件来生成一个 nuget 包。

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>ClassLibrary1</id>
    <version>1.0.0</version>
    <title>Title</title>
    <authors>Author</authors>
    <owners>Owner</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Description</description>
    <copyright>Copyright 2017</copyright>
    <contentFiles>
      <files include="any/any/myfile.xml" buildAction="None" copyToOutput="true" flatten="true" />
    </contentFiles>
  </metadata>
</package>

在构建引用此 nuget 包的项目时使用此配置,内容文件将被复制到输出文件夹。 现在我将我的项目转换为 .Net 核心项目,我想使用 project.json 来生成 nuget 包并摆脱 .nuspec 文件。 这是我的 project.json

{
  "version": "1.0.0-*",
  "dependencies": { },
  "frameworks": {
    "net452": {
    }
  },
  "packOptions": {
    "files": {
      "mappings": {
        "contentFiles/any/any/myfile.xml":  "Configuration/myfile.xml"
      }
    }
  },

  "scripts": {
    "postcompile": [
      "dotnet pack --no-build --configuration %compile:Configuration%"
    ]
  }
}

现在的问题是,在构建引用此 nuget 包的项目时,它也会尝试编译内容文件。并且构建失败。 如何从编译中排除 contentFile?

【问题讨论】:

    标签: c# asp.net-core nuget


    【解决方案1】:

    由于与脚本和转换类似的原因,目前已禁用对内容的支持,但我们正在设计对内容的支持。

    这是来自官方 nuget 文档页面。你可以找到here的信息。

    【讨论】:

      【解决方案2】:

      您不能在 ASP.NET 核心包中添加内容。你可以使用 bower/npm 包来代替使用内容。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-08-12
        • 2020-05-02
        • 1970-01-01
        • 1970-01-01
        • 2020-03-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多