nuspec contentFiles Example

Timothy Klenke picture Timothy Klenke · Dec 1, 2015 · Viewed 15.9k times · Source

Yesterday NuGet 3.3 was released (release notes) and there is a new contentFiles element supported (docs). However, I can't seem to get this working.

I'm using the NuGet.exe as the build process. It is updated to v3.3. I have also updated my Visual Studio to 2015 Update 1 and rebooted.

Here is my nuspec file (Hello.world.nuspec):

<?xml version="1.0" encoding="utf-8"?>
<package>
    <metadata minClientVersion="3.3">
        <id>Hello.world</id>
        <version>1.0.0</version>
        <title>Greeting library</title>
        <authors>Timothy Klenke</authors>
        <description>Greetings for the world</description>
    </metadata>
    <contentFiles>
        <files include="*" />
    </contentFiles> 
</package>

I run from the command line using the following:

nuget.exe update -Self
nuget.exe pack Hello.world.nuspec

And I get the following:

MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'. Attempting to build package from 'Hello.world.nuspec'. The element 'package' 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: 'files' in namespace 'http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd'.

I think I am running all the latest versions that should support the new contentFiles XML element, but the tools don't seem to know about it. What am I missing? I know the files include attribute is garbage, but does someone have a full example nuspec file using the new contentFiles element?

Answer

Peter Smolinsky picture Peter Smolinsky · Dec 2, 2015

Element <contentFiles> has to be inside <metadata> according to NuSpec reference. So it should look like this:

<?xml version="1.0" encoding="utf-8"?>
<package>
    <metadata minClientVersion="3.3">
        <id>Hello.world</id>
        <version>1.0.0</version>
        <title>Greeting library</title>
        <authors>Timothy Klenke</authors>
        <description>Greetings for the world</description>
        <contentFiles>
            <files include="*" />
        </contentFiles> 
    </metadata>
</package>