简体   繁体   中英

Connecting to TFS programatically throws Unauthorized error, unless visual studio is connected to TFS Project. How can i fix this?

I'm currently working in a WinForms app and using different .net client library to connect to TFS/Azure DevOps:

Microsoft.TeamFoundation.Client; Microsoft.VisualStudio.Services.Common;

and my IDE is Visual Studio 2015.

After trying to connect to TFS/Azure DevOps through diffrent methodes like:

1) Default Credentials

configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);

or

var tpc = new TfsConfigurationServer(tfsUri);
tpc.Authenticate();

2) VssCredentials with alternate credentails activated

var winCred = new Microsoft.VisualStudio.Services.Common.WindowsCredential(
var creds = new VssCredentials(winCred);
tfsCredential.AllowInteractive = false;

var tpc = new TfsConfigurationServer(tfsUri);
tpc.Authenticate();

I noticed that only TFS Sites that were already connected to my Visual Studio IDE connected properly. It didnt matter if I added credentials or not!

~ What seams to be the problem here?

~ How can I fix it?

~ What changes when I connect my IDE to TFS that allows me afterwards to connect to TFS programatically?

This is more likely the credentials were stored in your Credential Manager.

You should try to remove those. Refer this blog

Also you can refer this SO to remove the cached credentials from your Visual studio.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM