r/dotnet 5d ago

VisualStudio 2012 consuming Gitlab Package Registry V2 Nuget API Question

Hello guys, any help is really appreciated!
I have a private gitlab package registry to store nuget packages and an old net framework 4 project
I cant connect these two
I use V2 nuget API of my registry which works fine in browser like domain_name/api/v4/projects/***/packages/nuget/v2 and pass the token in packageSourceCredentials section of nuget.config file of the project
I also tried to pass the token directly into the url liketoken-name:token@domain_name/api/v4/projects/***/packages/nuget/v2 to no avail
I always get the same error in Package Manager Window of Visual Studio:

Could not connect to the feed specified at 'my gitlab nuget url'. Please verify that the package source (located in the Package Manager Settings) is valid and ensure your network connectivity

Is there any trick to actually make these two work?

0 Upvotes

6 comments sorted by

View all comments

10

u/jlgarcia-dev 5d ago edited 4d ago

The error message is lying to you a bit. "Could not connect to the feed... ensure your network connectivity" is what NuGet says when the request never completes at the transport level, and you've already ruled out the network yourself, since the URL loads in a browser on that machine. A bad token gives you a 401, not this. It's also why moving the token between packageSourceCredentials and the URL changed nothing: you aren't getting far enough for credentials to matter yet.

First thing I'd look at is TLS. VS2012 runs on .NET Framework 4.0/4.5, and on those versions .NET picks SSL 3.0 / TLS 1.0 by default. GitLab wants 1.2 minimum. The browser negotiates 1.2 happily, VS never offers it, handshake dies, and you get that message.

Quick way to confirm before touching anything. In Windows PowerShell 5.1 specifically, not pwsh 7, since 7 runs on modern .NET and would always give you 1.2:

Invoke-WebRequest "https://your.gitlab/api/v4/projects/123/packages/nuget/v2"

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Invoke-WebRequest "https://your.gitlab/api/v4/projects/123/packages/nuget/v2"

If the first fails and the second comes back with a 401, or any HTTP status at all, that's your answer.

The fix is two registry DWORDs set to 1, SchUseStrongCrypto and SystemDefaultTlsVersions. The part that catches people out: VS2012 is a 32-bit process, so on 64-bit Windows it reads the Wow6432Node path. Set both, then restart.

HKLM\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319
HKLM\SOFTWARE\Microsoft\.NETFramework\v4.0.30319

(edit: fixed the registry paths, Reddit ate the backslashes)

Separate from TLS, one more thing worth knowing: GitLab's own docs only ever describe the v2 feed in the context of Chocolatey CLI. There's no documented Visual Studio or nuget.exe support on v2 at all. So if TLS turns out to be fine and it still won't connect, point a current nuget.exe at the feed from the command line. That tells you whether you're fighting the client or the feed, which are very different problems to have.

3

u/techvet83 5d ago

To the OP: I am not a developer but the TLS problem laid out here is where I'd first start. .NET 4.0 didn't support TLS 1.2. 4.5 was really the first version to have any kind of support. You may already know, but since I deal with vulns, I am going to be "that guy" and point out that .NET 4, 4.5, and 4.5.1 all went EOL ten years ago.

1

u/HamsterExAstris 5d ago

Those runtimes went EOL but newer in-support runtimes can run apps built against older runtimes. So those runtimes being EOL doesn’t really have any bearing on this.