使用 C# 从 TFS 下载文件
Downloading Files from TFS using C#
我正在尝试使用 C# 编程从 TFS 下载我的代码文件。为了实现这一点,需要遵循两个步骤,
- 通过 C# 连接到 TFS
- 路由到下载所需文件的文件夹。
我目前正在执行第 1 步,为了实现,我做了一些研究并使用了 TFS API 并使用了以下代码,
public static bool AlwaysGoodCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors)
{
return true;
}
static void Main(string[] args)
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AlwaysGoodCertificate);
// Translate username and password to TFS Credentials
ICredentials networkCredential = new NetworkCredential(@"username", @"password", @"domain");
WindowsCredential windowsCredential = new WindowsCredential(networkCredential);
TfsClientCredentials tfsCredential = new TfsClientCredentials(windowsCredential, false);
// Connect to TFS Work Item Store
Uri tfsUri = new Uri(@"https://url");
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(tfsUri, tfsCredential);
WorkItemStore witStore = new WorkItemStore(tfs);
}
现在,我无法通过此代码连接到 TFS,每当我尝试通过输入相同的 url、密码、域和用户名来使用浏览器连接时,我都会成功登录,但出于某些奇怪的原因我无法使用我的代码登录。当我尝试通过代码登录时收到以下错误,
正如 Shayki Abramczyk 在 url 中建议使用集合名称一样。
所以我使用了下面的 URL 它解决了我的问题,
https://server-name:443/tfs/Collection-name
我正在尝试使用 C# 编程从 TFS 下载我的代码文件。为了实现这一点,需要遵循两个步骤,
- 通过 C# 连接到 TFS
- 路由到下载所需文件的文件夹。
我目前正在执行第 1 步,为了实现,我做了一些研究并使用了 TFS API 并使用了以下代码,
public static bool AlwaysGoodCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors)
{
return true;
}
static void Main(string[] args)
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AlwaysGoodCertificate);
// Translate username and password to TFS Credentials
ICredentials networkCredential = new NetworkCredential(@"username", @"password", @"domain");
WindowsCredential windowsCredential = new WindowsCredential(networkCredential);
TfsClientCredentials tfsCredential = new TfsClientCredentials(windowsCredential, false);
// Connect to TFS Work Item Store
Uri tfsUri = new Uri(@"https://url");
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(tfsUri, tfsCredential);
WorkItemStore witStore = new WorkItemStore(tfs);
}
现在,我无法通过此代码连接到 TFS,每当我尝试通过输入相同的 url、密码、域和用户名来使用浏览器连接时,我都会成功登录,但出于某些奇怪的原因我无法使用我的代码登录。当我尝试通过代码登录时收到以下错误,
正如 Shayki Abramczyk 在 url 中建议使用集合名称一样。
所以我使用了下面的 URL 它解决了我的问题,
https://server-name:443/tfs/Collection-name