Nuget pack ignores specified files

Dec 1, 2010 at 2:57 PM
Edited Dec 1, 2010 at 3:40 PM

It seems to me, that no matter what i specify in the nuspec files section, nuget always adds the complete directory to the package. Even if I specify a File that does not even exist nuget doesn't complain.

I am using nuget command line version 0.5.46.0

<?xml version="1.0" encoding="utf-8"?>
<package>
  <metadata>
    <id>MyId</id>
    <version>1.0.0.1</version>
    <description>Blah Blah</description>
    <authors>
      <author>Meinrad Jean-Richard</author>
    </authors>
    <language>de-DE</language>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
  </metadata>
  <files>
    <file src="doesnotexist.xxx" target="lib" />
  </files>
</package>

Nuget pack says "Successfully created package" and when I look into the nupkg file, then the complete source folder with all its files is in it.

What am i doing wrong?

 

<?xml version="1.0" encoding="utf-8"?>
<package>
  <metadata>
    <id>MyId</id>
    <version>1.0.0.1</version>
    <description>Blah Blad</description>
    <authors>
      <author>Meinrad Jean-Richard</author>
    </authors>
    <language>de-DE</language>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
  </metadata>
  <files>
    <file src="doesnotexist.xxx" target="lib" />
  </files>
</package>
Developer
Dec 1, 2010 at 5:13 PM

The XmlSerializer that we use to read the manifest file acts wonky at times if you don’t include namespaces.

Could you change your spec file to the following and see if it works:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>MyId</id>
<version>1.0.0.1</version>
<description>Blah Blad</description>
<authors>
<author>Meinrad Jean-Richard</author>
</authors>
<language>de-DE</language>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
</metadata>
<files xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<file src="doesnotexist.xxx" target="lib" />
</files>
</package>

From: mjeanrichard [mailto:notifications@codeplex.com]
Sent: Wednesday, December 01, 2010 7:58 AM
To: Pranav Krishnamoorthy
Subject: Nuget pack ignores specified files [nuget:236724]

From: mjeanrichard

It seems to me, that no matter what i specify in the nuspec files section, nuget always adds the complete directory to the package. Even if I specify a File that does not even exist nuget doesn't complain.

I am using nuget command line version 1.0.0.0

<?xml version="1.0" encoding="utf-8"?>
<package>
  <metadata>
    <id>MyId</id>
    <version>1.0.0.1</version>
    <description>Blah Blah</description>
    <authors>
      <author>Meinrad Jean-Richard</author>
    </authors>
    <language>de-DE</language>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
  </metadata>
  <files>
    <file src="doesnotexist.xxx" target="lib" />
  </files>
</package>

Nuget pack says "Successfully created package" and when I look into the nupkg file, then the complete source folder with all its files is in it.

What am i doing wrong?

<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
<id>MyId</id>
<version>1.0.0.1</version>
<description>Blah Blad</description>
<authors>
<author>Meinrad Jean-Richard</author>
</authors>
<language>de-DE</language>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
</metadata>
<files>
<file src="doesnotexist.xxx" target="lib" />
</files>
</package>

Read the full discussion online.

To add a post to this discussion, reply to this email (nuget@discussions.codeplex.com@discussions.codeplex.com)

To start a new discussion for this project, email nuget@discussions.codeplex.com@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Developer
Dec 1, 2010 at 5:16 PM

You shouldn't need to specify the attributes, if it works only when you do, then please file a bug.

Dec 1, 2010 at 6:14 PM

I had a quick look at the Code and it seems to me that the Manifest class expects the xml to look like this (note the location of the files tag):

<?xml version="1.0" encoding="utf-8"?>
<package>
  <metadata>
    <id>MyId</id>
    <version>1.0.0.1</version>
    <description>Blah Blah</description>
    <authors>
      <author>Meinrad Jean-Richard</author>
    </authors>
    <language>de-DE</language>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <files>
      <file src="doesnotexist.xxx" target="lib" />
    </files>
  </metadata>
</package>
Which is not in accordance with the schema. The question is whether the code or the schema is correct?

Coordinator
Dec 1, 2010 at 10:18 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Developer
Dec 2, 2010 at 7:29 AM

Ok there's a pretty subtle issue here, the way you define your authors in the nuspec you have is wrong. It's nothing to do with the <files section> (we'll have to improve this error handling in v1.1). For now you can do this:

<?xml version="1.0" encoding="utf-8"?>
<package>
  <metadata>
    <id>MyId</id>
    <version>1.0.0.1</version>
    <description>Blah Blah</description>
    <authors>
         Meinrad Jean-Richard
    </authors>
    <language>de-DE</language>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <files>
      <file src="doesnotexist.xxx" target="lib" />
    </files>
  </metadata>
</package>

<authors> is not structured xml but is a comma separated string (it's been that way since CTP2).

Dec 2, 2010 at 8:59 AM

Yes, that seems to be another error in my nuspec File, but it has IMHO nothing to do with the behaviour I am talking about.

My point is, that this works (it only includes the file 'myfile.cs'):

<?xml version="1.0" encoding="utf-8"?>
<package>
  <metadata>
    <id>MyId</id>
    ... any metadata ...
    <files>
      <file src="myfile.cs" target="lib" />
    </files>
  </metadata>
</package>

whereas this does not work (all files of the working dir are included):

<?xml version="1.0" encoding="utf-8"?>
<package>
  <metadata>
    <id>MyId</id>
    ... any metadata ...
  </metadata>
  <files>
    <file src="myfile.cs" target="lib" />
  </files>
</package>

BUT: According to the schema the first version is wrong, and the second is correct...

Sorry if I wasn't precise enough in my first post.

 

Developer
Dec 2, 2010 at 9:10 AM
Edited Dec 2, 2010 at 9:10 AM

The second one is correct. If the first one works, then it's a bug, but the first one isn't what the code expects. If you look at the definition:

 

[XmlType("package", Namespace = Constants.ManifestSchemaNamespace)]
public class Manifest {
    public Manifest() {
        Metadata = new ManifestMetadata();
    }

    [XmlElement("metadata", IsNullable = false)]
    public ManifestMetadata Metadata { get; set; }

    [XmlArray("files")]
    [XmlArrayItem("file", IsNullable = false)]
    public List<ManifestFile> Files { get; set; }
    
}

 

The files node is outside of the metadata node in the schema and in the code.

The fact that the first one works mine be some oddities with how xml deserialzation handles unexpected attributes. But if you define all of the elements as expected, the second one will work.

Dec 2, 2010 at 11:13 AM

Ah, yes, I see. I got confused because it worked with the files tag within the metadata tag.

It would be nice if nuget validate the whole nuspec file against the schema, so that one can find such an error quickly.

Thanks for your help.

Developer
Dec 2, 2010 at 3:50 PM

I totally agree. We've filed a bug for 1.1 to do schema validation. http://nuget.codeplex.com/workitem/423