简体   繁体   English

使用project.json在nuget包中包含内容文件

[英]Include content files in nuget package using project.json

I'm using this .nuspec file to generate a nuget package. 我正在使用此.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>

Using this configuration when building a project that references this nuget package the content files will be copied to the output folder. 在构建引用此nuget包的项目时使用此配置,内容文件将被复制到输出文件夹。 Now I'm converting my project into .Net core project and i want to use the project.json to generate the nuget package and get rid of the .nuspec file. 现在我将我的项目转换为.Net核心项目,我想使用project.json生成nuget包并删除.nuspec文件。 This is my project.json 这是我的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%"
    ]
  }
}

Now the problem is that when building a project that references this nuget package it will try to compile the content file too. 现在的问题是,当构建一个引用这个nuget包的项目时,它也会尝试编译内容文件。 And the build fails. 构建失败了。 How can I exclude the contentFile from compilation? 如何从编译中排除contentFile?

Support for content is currently disabled for similar reasons for scripts and transforms, but we are in the process of designing support for content. 由于脚本和转换的类似原因,目前对内容的支持已被禁用,但我们正在设计对内容的支持。

This is from the official nuget documentation page. 这来自官方的nuget文档页面。 You can find the infos here . 你可以在这里找到这些信息。

You cannot add contents in ASP.NET core packages. 您无法在ASP.NET核心包中添加内容。 You can go for bower/npm packages instead to use contents. 您可以使用bower / npm包来代替使用内容。

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

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