4
votes

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?

2

2 Answers

1
votes

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.

1
votes

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