For windows native applications which want to target both VSTS and TFS we recommend using the Client Libraries for VSTS and TFS to generate interactive sign in prompts for VSTS users and leverage seemless Windows credential authentication for TFS users.
This buildable sample will walk you through the steps to create a client-side console application which uses Client Libraries - Interactive and Windows Auth to authenticate a VSTS or TFS user and return a list of all projects inside a selected VSTS account or TFS collection.
To run this sample you will need:
From a shell or command line:
git clone https://github.com/Microsoft/vsts-auth-samples.git
Packages: Microsoft.VisualStudio.Services.Client, and Microsoft.TeamFoundation.Core.WebApi have already been installed and configured in the sample, but if you are adding to your own project you will need to install and configure it yourself.
- Navigate to the ADAL C# sample in cloned repo
vsts-auth-samples/DualSupportClientSample/
. - Open the solution file
VstsTfsSample.sln
in Visual Studio 2017. - Use Nuget package restore to ensure you have all dependencies installed.
- Open CS file
Program.cs
and there is a section with input values to change at the top of the class:vstsOrTfsCollectionUrl
- update this with the url to your VSTS/TFS collection, e.g. http://myaccount.visualstudio.com for VSTS or http://myserver:8080/tfs/DefaultCollection for TFS.
- Build and run the solution. After running you should see an interactive login prompt if you are a VSTS user. If you are a TFS user authentication should happen in the background. After authentication and authorization, a list of all projects inside of your account will be displayed in the console.