13

I am trying to use the following Cake script:

Task("Create-NuGet-Packages")
    .IsDependentOn("Build")
    .WithCriteria(() =>DirectoryExists(parameters.Paths.Directories.NugetNuspecDirectory))
    .Does(() =>
{
    var nuspecFiles = GetFiles(parameters.Paths.Directories.NugetNuspecDirectory + "/**/*.nuspec");

    EnsureDirectoryExists(parameters.Paths.Directories.NuGetPackages);

    foreach(var nuspecFile in nuspecFiles)
    {
        // TODO: Addin the release notes
        // ReleaseNotes = parameters.ReleaseNotes.Notes.ToArray(),

        // Create packages.
        NuGetPack(nuspecFile, new NuGetPackSettings {
            Version = parameters.Version.SemVersion,
            BasePath = parameters.Paths.Directories.PublishedLibraries.Combine(nuspecFile.GetFilenameWithoutExtension().ToString()),
            OutputDirectory = parameters.Paths.Directories.NuGetPackages,
            Symbols = false,
            NoPackageAnalysis = true
        });
    }
});

But I keep getting the same error:

Error returned from NuGetPack

I have confirmed that the generated *.temp.nuspec file does indeed contain the correct files, and that the files exist within the specified location, and that the BasePath is correct.

NOTE: I have used -Verbosity Diagnostic to generate the actual command that is being passed to NuGet.exe, and running that directly also results in the same error message. As a result, I don't think that this is a problem directly with Cake, but rather with NuGet.exe.

Gary Ewan Park
  • 17,610
  • 5
  • 42
  • 60
  • 1
    Make sure you are using latest NuGet. One can run `nuget update -self` to have latest version installed. – Alex Sorokoletov Jan 27 '17 at 15:24
  • In my case, I found the following comment in that GitHub thread you linked to elucidating: `unfortunately, the way the application is written, will require substantial re-work to determine if something was included as a result of being hardcoded or as a result of wildcard. It's especially more difficult with dotnet.exe pack / msbuild /t:pack where msbuild resolves all the wildcards and passes NuGet a full list of files.` – John Zabroski Jun 14 '21 at 16:54

3 Answers3

6

Turns out, this was an error with the directory paths that I was using. I was trying to use .build\_temp\_PublishedLibraries\Cake.Twitter.

Changing .build to BuildArtifacts immediately made everything work:

enter image description here

After doing a little bit of digging, this seems to be a known issue with NuGet (well at least known to some):

https://twitter.com/ferventcoder/status/505048107520765952

i.e. Any file or folder that start with a . are not recognised by nuget pack.

Seemingly this issue has been corrected in Chocolatey, and as a result, it works there.

NOTE: I have raised this as an issue here: https://github.com/NuGet/Home/issues/3308

Gary Ewan Park
  • 17,610
  • 5
  • 42
  • 60
  • 1
    I found the following comment in that GitHub thread you linked to elucidating: `unfortunately, the way the application is written, will require substantial re-work to determine if something was included as a result of being hardcoded or as a result of wildcard. It's especially more difficult with dotnet.exe pack / msbuild /t:pack where msbuild resolves all the wildcards and passes NuGet a full list of files.` In other words, the problem is that MSBuild may not know you have a .nuspec file that has wildcards in it. – John Zabroski Jun 14 '21 at 17:15
4

In my case problem was using forward slash / instead of backslash \ - it is probably related to the https://github.com/NuGet/Home/issues/3584

Martin Schneider
  • 14,263
  • 7
  • 55
  • 58
user1121956
  • 1,843
  • 2
  • 20
  • 34
3

This error can also be seen if you simply specify a bad path/spec in the <file src attribute and NuGet gathers no files.

Luke Puplett
  • 42,091
  • 47
  • 181
  • 266