简体   繁体   中英

Include content files in nuget package using project.json

I'm using this .nuspec file to generate a nuget package.

<?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. 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. This is my 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. And the build fails. How can I exclude the contentFile from compilation?

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. You can find the infos here .

You cannot add contents in ASP.NET core packages. You can go for bower/npm packages instead to use contents.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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