You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
NuGet.Home/accepted/archive/PackageValidation/FileNameCaseSensitivity.md

4.6 KiB

Error on improper file name case

  • Status: Implemented
  • Author(s): David Maas
  • Issue: 9817 NU5030 license file existence check should always use a case-sensitive comparison

Problem Background

Presently when you pack a NuGet package on Windows, it is possible to specify diferent casing for the filename for PackageLicenseFile/PackageIcon. For instance, you can pack a file named License.txt and specify <PackageLicenseFile>LICENSE.txt</PackageLicenseFile> in the NuSpec and the package will pack without errors.

However, this package is malformed because NuGet packages are zip files and zip files use case-sensitive paths internally. As a consequence, the package cannot be uploaded to NuGet.org:

Screenshot of NuGet.org upload page with error: "The license file 'LICENSE.txt' does not exist in the package."

If you attempt to put the package in a local feed (or another feed which does not perform this check), you'll get an error:

Screenshot of Visual Studio error message: "Unknown problem loading the file 'LICENSE.txt'."

Who are the customers

This primarily affects package authors who may be unknowingly packing malformed packages.

Goals

  • Prevent package authors from making this mistake.
  • Avoid breaking packages which exhibit this problem.
    • Not all package feeds can or will verify the license or icon file exists. (IE: Local package feeds, Nexus Repository)
  • Fix the behavioral inconsistency between packing on Windows/macOS vs Linux.

Non-Goals

Changing the behavior of packing on Linux is a non-goal.

Solution

Expand the scope of existing errors to cover attempting to pack a package with improper casing on the PackageLicenseFile/PackageIcon:

NU5030: The license file 'LICENSE.txt' does not exist in the package. (Did you mean 'License.txt'?)
NU5046: The icon file 'Icon.png' does not exist in the package. (Did you mean 'icon.png'?)

As shown above, in the situation NuGet will give a hint to the user with the correct casing.

Future Work

A warning is specified to avoid breaking packages which previously packed successfully even though they were malformed. In a future .NET SDK release, this warning could become an error by default similar to NU1605.

Open Questions

None.

Considerations

It was considered to make the issue a warning, but this would expose the user to a pit of failure.

It was considered to make new error codes for this case, but was deemed unecessary.

It was considered that packing could silently update PackageLicenseFile to the correct value, but this behavior seems like it has the potential to be confusing.

If this were to be a warning, it was considered changing the behavior on Linux to use a case-insensitive string comparison as well in order to make these malformed packages packable there, but that was deemed unecessary. (And it turns what is an error today into a warning.)

It was considered that when the file was found but in a different directory that the hint could appear in that situation too, but this situation was deemed to be out of scope.

References

The source of the issue:

Zip files are always case-sensitive, so the use of GetStringComparisonBasedOnOS in both instances is incorrect.


A modified NuGet samples exhibiting the issue: