NuGet / Home

Repo for NuGet Client issues
Other
1.49k stars 252 forks source link

5.3.0 regression - Index was outside the bounds of the array with basic nuspec file (NU5129) #8703

Closed megakid closed 4 years ago

megakid commented 4 years ago

Can anyone explain the following - I'm pretty sure something isn't right but can't figure out what.

We had a build failure on our CI server today caused by the release of NuGet.CommandLine 5.3.0 - we have now pinned our build to 5.2.0 to work around the issue.

Here's our .nuspec file:

<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>Squid.FullDeploy</id>
    <version>$version$</version>
    <authors>My Team</authors>    
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>BALH</description>
    <tags>BLAH</tags>
    <copyright>SOMETHING</copyright>
  </metadata>
  <files>
    <file src="*" exclude="*.nuspec" />
    <file src="buildtime-vars.json" />
  </files>
</package>

Comparing the two versions, side-by-side:

C:\Projects\squid3\src\Squid.FullDeploy>..\..\tools\NuGet.CommandLine.5.3.0\tools\NuGet.exe pack Squid.FullDeploy.nuspec -version 3.43.7
Attempting to build package from 'Squid.FullDeploy.nuspec'.
Successfully created package 'C:\Projects\squid3\src\Squid.FullDeploy\Squid.FullDeploy.3.43.7.nupkg'.
Index was outside the bounds of the array.

C:\Projects\squid3\src\Squid.FullDeploy>..\..\tools\NuGet.CommandLine.5.2.0\tools\NuGet.exe pack Squid.FullDeploy.nuspec -version 3.43.7
Attempting to build package from 'Squid.FullDeploy.nuspec'.
WARNING: NU5119: File 'C:\Projects\squid3\src\Squid.FullDeploy\Squid.FullDeploy.3.43.7.nupkg' was not added to the package. Files and folders starting with '.' or ending with '.nupkg' are excluded by default. To include this file, use -NoDefaultExcludes from the commandline
Successfully created package 'C:\Projects\squid3\src\Squid.FullDeploy\Squid.FullDeploy.3.43.7.nupkg'.
WARNING: NU5110: The script file 'cakebootstrapper.ps1' is outside the 'tools' folder and hence will not be executed during installation of this package. Move it into the 'tools' folder.
WARNING: NU5110: The script file 'deploy.ps1' is outside the 'tools' folder and hence will not be executed during installation of this package. Move it into the 'tools' folder.
WARNING: NU5111: The script file 'cakebootstrapper.ps1' is not recognized by NuGet and hence will not be executed during installation of this package. Rename it to install.ps1, uninstall.ps1 or init.ps1 and place it directly under 'tools'.
WARNING: NU5111: The script file 'deploy.ps1' is not recognized by NuGet and hence will not be executed during installation of this package. Rename it to install.ps1, uninstall.ps1 or init.ps1 and place it directly under 'tools'.
marhel commented 4 years ago

We get the same IndexOutOfRangeException with NuGet.exe 5.4.0.6315. Running NuGet.exe pack with -Verbosity detailed gives us the call stack, pointing to NuGet.Packaging.Rules.UpholdBuildConventionRule.GetFolderName.

As I (and @megakid) both had nuspec files trying to place a file in the package root folder, I guess that UpholdBuildConventionRule.GetFolderName does not handle files without a folder component.

Successfully created package 'C:\src\github\factor10\x10-build\build\x10.BuildScript.1.0.0.nupkg'.
Index was outside the bounds of the array.
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at NuGet.Packaging.Rules.UpholdBuildConventionRule.GetFolderName(String filePath)
   at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.GroupedEnumerable`3.GetEnumerator()
   at NuGet.Packaging.Rules.UpholdBuildConventionRule.IdentifyViolators(IEnumerable`1 files, String packageId)
   at NuGet.Packaging.Rules.UpholdBuildConventionRule.Validate(PackageArchiveReader builder)
   at NuGet.Commands.PackCommandRunner.AnalyzePackage(PackageArchiveReader package)
   at NuGet.Commands.PackCommandRunner.BuildFromNuspec(String path)
   at NuGet.Commands.PackCommandRunner.BuildPackage()
   at NuGet.CommandLine.PackCommand.ExecuteCommand()
   at NuGet.CommandLine.Command.ExecuteCommandAsync()
   at NuGet.CommandLine.Command.Execute()
   at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)

In our case the offending line is

<file src="FAKE\*.fsx" target="" />

If I remove this (or make it not actually match a file) then packaging succeeds (although we also get warnings, in our case NU5101 which recommends not placing dlls directly under the lib folder)

nkolev92 commented 4 years ago

@zivkan Related to https://github.com/NuGet/Home/issues/9388 & https://github.com/NuGet/Home/issues/9055

jannikbuschke commented 4 years ago

Hitting the same issue. Pinning nuget 5.2 solves the issue for the time being.