Access Tokens Stop Working in Visual Studio

I have created a package registry in our self-managed GitLab instance, to which I have published a handful of bespoke NuGet packages for internal use. In Visual Studio 2022 I have successfully added our package registry as a package source, so I’m able to browse the packages in the VS package manager, download updates to them and so on.

To add the registry as a package source in Visual Studio I had to authenticate, when prompted, using my GitLab username and, in place of a password, an access token that I created in GitLab with the read_api permission. As I said, this worked just fine, but the problem is that after a few days, when I open the pacakge manager in Visual Studio I’ll get an authentication error when it tries to connect to our package registry.

The first time this happened I assumed that I must have created the access token with a short expiry time, so I created a new token, re-authenticated, and it worked again. However, this has now happened dozens of times and I’m certain that I’m creating tokens which don’t expire for many months, yet they always stop working after a few days. When I look at the list of tokens in the GitLab web interface, they have not expired. But each time, my only option is to delete the old token, create a new one, open Windows Credential Manager and replace the password saved against my GitLab account (not the one I use for Git actions, which seems to be separate), which fixes the issue for another few days.

All of my colleagues who are using our package registry are experiencing the same problem and it’s very frustrating! Since the troublesome access tokens always show as unexpired in GitLab I don’t know whether the problem here is with GitLab or with Windows, but I have no idea what to do about it. Does anybody have any ideas?