Unable to restore NuGet packages with 4 digit version number and last digit is 0
Summary
NuGet package with 4 digit version and the last digit being a 0 is not found when using nuget.exe restore
Steps to reproduce
- Create NuGet package: Tool.Dummy.Test.1.0.25.0.nupkg
- Push nuget package to the server:
nuget push ../nuget_packages/Tool.Dummy.Test.1.0.25.0.nupkg -Source [Your NuGet Source]
- Create packages.config file:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Tool.Dummy.Test" version="1.0.25.0" />
</packages>
- Execute command:
nuget restore -PackagesDirectory . -Source [Your NuGet Source]
Example Project
https://gitlab.com/hvandenwijngaerden/fourdigitversion
- Checkout repository
- Add nuget source to the project
- Run the command:
nuget restore -PackagesDirectory . -Source [Your NuGet Source]
What is the current bug behavior?
Unable to find the NuGet package: Unable to find version '1.0.25' of package 'Tool.Dummy.Test'.
What is the expected correct behavior?
Package found and installed in the current folder
Relevant logs and/or screenshots
PS C:\dev\GitLabPacketIssue\FourDigitVersion> nuget restore -PackagesDirectory . -Source FourDigitVersion
Restoring NuGet package Tool.Dummy.Test.1.0.25.
GET https://gitlab.com/api/v4/projects/22114084/packages/nuget/download/tool.dummy.test/1.0.25/tool.dummy.test.1.0.25.nupkg
NotFound https://gitlab.com/api/v4/projects/22114084/packages/nuget/download/tool.dummy.test/1.0.25/tool.dummy.test.1.0.25.nupkg 865ms
WARNING: Unable to find version '1.0.25' of package 'Tool.Dummy.Test'.
C:\Users\hvandenwijngaerden\.nuget\packages\: Package 'Tool.Dummy.Test.1.0.25' is not found on source 'C:\Users\hvandenwijngaerden\.nuget\packages\'.
https://gitlab.com/api/v4/projects/22114084/packages/nuget/index.json: Package 'Tool.Dummy.Test.1.0.25' is not found on source 'https://gitlab.com/api/v4/projects/22114084/packages/nuget/index.json'.
WARNING: Unable to find version '1.0.25' of package 'Tool.Dummy.Test'.
C:\Users\hvandenwijngaerden\.nuget\packages\: Package 'Tool.Dummy.Test.1.0.25' is not found on source 'C:\Users\hvandenwijngaerden\.nuget\packages\'.
https://gitlab.com/api/v4/projects/22114084/packages/nuget/index.json: Package 'Tool.Dummy.Test.1.0.25' is not found on source 'https://gitlab.com/api/v4/projects/22114084/packages/nuget/index.json'.
Errors in packages.config projects
Unable to find version '1.0.25' of package 'Tool.Dummy.Test'.
C:\Users\hvandenwijngaerden\.nuget\packages\: Package 'Tool.Dummy.Test.1.0.25' is not found on source 'C:\Users\hvandenwijngaerden\.nuget\packages\'.
https://gitlab.com/api/v4/projects/22114084/packages/nuget/index.json: Package 'Tool.Dummy.Test.1.0.25' is not found on source 'https://gitlab.com/api/v4/projects/22114084/packages/nuget/index.json'.
NuGet Config files used:
C:\Users\hvandenwijngaerden\AppData\Roaming\NuGet\NuGet.Config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
Feeds used:
C:\Users\hvandenwijngaerden\.nuget\packages\
https://gitlab.com/api/v4/projects/22114084/packages/nuget/index.json
PS C:\dev\GitLabPacketIssue\FourDigitVersion>
Output of checks
Bug happens on self-managed and GitLab.com
Results of GitLab environment info
Results of GitLab application Check
Possible fixes
I think the issues comes from the version string matching and the filename matching. When requesting the package, nuget.exe changes the version to a 3 digit version stripping away the last 0. This potentially makes that the packet version cannot be matched. I added a little loop to the function packages
from the file app\finders\packages\nuget\package_finder.rb
to append .0
if no match was found. This would resolve the first step and possibly there is a better way of solving this. But also afterwards in the file app\finders\packages\package_file_finder.rb
the function by_file_name
will not find a match for the NuGet package file.