It depends on the version of your TFS. However, if you're trying to connect to TFS2015, or TFS2017, this will do;
using Microsoft.TeamFoundation.Client;
using Microsoft.VisualStudio.Services.Common;
using System;
using System.Net;
namespace TFSConsoleApp
{
class Program
{
static void Main(string[] args)
{
NetworkCredential networkCredentials = new NetworkCredential(@"Domain\Account", @"Password");
Microsoft.VisualStudio.Services.Common.WindowsCredential windowsCredentials = new Microsoft.VisualStudio.Services.Common.WindowsCredential(networkCredentials);
VssCredentials basicCredentials = new VssCredentials(windowsCredentials);
TfsTeamProjectCollection tfsColl = new TfsTeamProjectCollection(
new Uri("http://XXX:8080/tfs/DefaultCollection"),
basicCredentials);
tfsColl.Authenticate(); // make sure it is authenticate
}
}
}
I cannot stress enough to ensure the credentials are a-okay! This error has occured to me a couple times too.
There is also another solution if the above doesn't work.
- Close Visual Studio and go to Control Panel
- User Accounts --> Manage your Credentials (on the left column)
- Select "Windows Credentials"
- Scroll down to the "Generic Credentials" section and look for
your TFS server connection
- Expand the pull down and click "Edit"
- Enter in your network password
- Restart Visual Studio and retry the code