sourcelink: SourceLink Authentication error when using Microsoft.SourceLink.AzureRepos.Git

I am trying to enable SourceLink for our internal NuGet packages and am running into a problem where I don’t see how I can solve it.

My setup is:

  • Visual Studio 2019 Enterprise (16.3.8)
  • An Azure DevOps git repository
  • A .NET Framework 4.7.2 class library with an SDK style project containing a single HelloWorld class
  • A PackageReference to Microsoft.SourceLink.AzureRepos.Git, using the latest Version (1.0.0-beta2-19554-01)

This project generates a package that includes the DLL and the PDB (I know this is discouraged, but I would like to get it to work this way rather than using a symbol server; this also does not seem to be the source of the problem, since the debugger finds the correct PDB)

The project file

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
    <RepositoryUrl>https://<host>.visualstudio.com/<project>/_git/Lib</RepositoryUrl>
    <RepositoryType>git</RepositoryType>
    <AssemblyVersion>2.0.0.0</AssemblyVersion>
    <FileVersion>2.0.0.0</FileVersion>
    <Version>2.0.0</Version>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.SourceLink.AzureRepos.Git" Version="1.0.0-beta2-19554-01">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>
</Project>
  • I commit my changes to the repository and build the package. The package builds fine. When I check the generated .nuspec file, it contains the correct commit hash.
  • I publish it to a local NuGet feed using nuget add Lib.2.0.0.nupkg -Source C:\NuGet.
  • I delete my local HelloWorld sources so the debugger does not find these sources and tries to download them from the git repository
  • I create a console application, reference this NuGet package, and call the HelloWorld function on the HelloWorld class. In the debugger, I hit F11 to step into the HelloWorld call. The “SourceLink will download […]” dialog box appears and I select “Download Source and Continue Debugging”.

This does not work. I get the following error message

Source Link Error:
ERROR: Azure DevOps: Authentication failed for all accounts. Use 'File -> Account Settings...' to add a new account or refresh credentials.

Source Link URL: https://<host>.visualstudio.com/<project>/_apis/git/repositories/Lib/items?api-version=1.0&versionType=commit&version=cf94d5a0f224b6983c3885a2a6ac29aa52cec418&path=/HelloWorld/HelloWorld.cs

Now, the error message is pretty clear, I just don’t get it. When I go to the URL stated in the error message, I see the file content I am expecting. I used a browser I never use to check, and when navigating to this page, it asked me to sign in, and I do so using the same account I use in Visual Studio. I also tried signing out of Visual Studio, restarting it, and signing in again to Visual Studio using the same account I used in the browser. Still the same error.

Any idea what I could be doing wrong?

Thanks, David

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 1
  • Comments: 35 (11 by maintainers)

Most upvoted comments

Faced the same issue with source link and our private Bitbucket server. Use Internet Explorer on local machine and authorize in your VCS with password saving IE saves password in Windows Credential Manager (Web Credential) And seems like source link uses credential exactly from here (in case authorization is required)

Bump.

Good to have this confirmed, thanks for the information. Sadly this is not an option for us for quite some time. I guess we’ll have to look for another solution since it doesn’t seem there’s anything going forward here.

Right, I’ve got to the bottom of the issue on my end. It was an issue with Microsoft vs AD account. Turns out I was looking at it the wrong way around, and assumed my devops account was using my AD account.

I was attempting to authenticate to devops via sourcelink with an Azure AD account. Turns out my devops account is actually pointed at a Microsoft account, so logging in as another user (but then using same email), then selecting the “home” account worked.

So in all, the fix should be as simple as adding the AD account to devops.

@mvonballmo @dmuehlenhoff I’d suggest checking the same on your end.

@scp-mb I did talk to chuck a bit via mail, but the issue has never been resolved; his last statement is he needs to wait for people who know more about Azure DevOps and they’re not available right now. That has been 2 months ago though, so I’m not sure what’s going to happen.

The reason for the error in my case seems to be that we are using users from different tenants (our Azure DevOps is on a different tenant than the users that access it), and this leads to a mix of Azure AD and MSA authentication, which cannot be handled by the current SourceLink implementation.

@dmuehlenhoff That looks ok. You have the right package (Microsoft.SourceLink.AzureRepos.Git).