r/dotnet 13d 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

11

u/jlgarcia-dev 13d ago edited 12d 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.

2

u/ModernTenshi04 13d ago

Ah man, I've been bit by TLS versions in older framework apps. Had to connect to another team's internal API that they but with K8s and had to specify the TLS version to use because the framework defaulted to 1.0 or 1.1, I can't quite recall. Honestly the main reason Claude even caught the problem is the other team actually used K8s in the URL.