Search code examples
nugetnuget-packagenuspec

nuspec contentFiles element invalid in metadata


I have included the following in my nuspec file:

<?xml version="1.0"?>
<package>
    <metadata minClientVersion="3.3">
        <contentFiles>
            <file src="*.css" target="_css" />
        </contentFiles>
    </metadata>
</package>

However, I get the following error:

MSBUILD : OctoPack error OCTONUGET: The element 'metadata' in namespace 'http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd' has invalid child element 'contentFiles' in namespace 'http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd'. List of possible elements expected: 'language, licenseUrl, projectUrl, requireLicenseAcceptance, summary, tags, frameworkAssemblies, title, references, copyright, authors, description, version, iconUrl, owners, dependencies, id, developmentDependency, releaseNotes' in namespace 'http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd'.

When I look here: https://blog.nuget.org/20160126/nuget-contentFiles-demystified.html, what I've done seems correct. What am I missing?


Solution

  • There were two problems with this.

    One was as per the 'BikerDude' answer.

    The second that the target did not begin with

    lib, content, build, or tools

    as per the documentation.

    My final markup looked like this:

    <?xml version="1.0"?>
    <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
        <metadata minClientVersion="3.3">
            <id>Application Id</id>
            <version>$version$</version>
            <description>Solution description</description>
            <authors>Development Team</authors>
        </metadata>
        <files>
            <file src="\_css\**\*.*" target="content\_css" />
            <file src="\_scripts\**\*.*" target="content\_scripts" />
            <file src="\_images\**\*.*" target="content\_images" />
        </files>
    </package>
    

    I then created a virtual directory in IIS for the 'content' directory, so that the file references did not need to change.