title: Connect to TFS programmatically from vs 2017
body: <p>I am using <code>TFS 15.x. package</code>. </p>
  
  <p>Error:</p>
  
  <blockquote>
    <p>Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException:
    'TF30063: You are not authorized to access
    "<a href="https://myproject.visualstudio.com/RpaCodeReview" rel="nofollow noreferrer">https://myproject.visualstudio.com/RpaCodeReview</a>'</p>
  </blockquote>
  
  <pre><code>Uri Repurl = new Uri("https://myproject.visualstudio.com/RpaCodeReview");
  NetworkCredential netCred = new NetworkCredential(username, password);
  VssBasicCredential basicCred = new VssBasicCredential(netCred);
  VssCredentials tfsCred = new VssCredentials(basicCred);
  TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(Repurl, tfsCred);
  tpc.EnsureAuthenticated();
  </code></pre>