我正在创建我的第一个 ASP.NET MVC 项目。我已经开始连接 TFS 并通过 C# 将错误添加到 TFS 中。
var tfsURI = new Uri("http://test:8080/tfs");
var networkCredential1 = new NetworkCredential("test", "test!");
ICredentials credential = (ICredentials)networkCredential1;
Microsoft.VisualStudio.Services.Common.WindowsCredential winCred = new Microsoft.VisualStudio.Services.Common.WindowsCredential(credential);
VssCredentials vssCredentials = new VssCredentials(winCred);
using (TfsTeamProjectCollection collection = new TfsTeamProjectCollection(tfsURI, vssCredentials))
{
collection.EnsureAuthenticated();
WorkItemStore workItemStore = collection.GetService<WorkItemStore>();
Project teamProject = workItemStore.Projects["Test"];
WorkItemType workItemType = teamProject.WorkItemTypes["Bug"];
WorkItem Defect = new WorkItem(workItemType);
FileInfo fi = new FileInfo(@"C:\\Document.docx");
Attachment tfsAttachment = new Attachment(fi.FullName);
Defect.Attachments.Add(tfsAttachment);
Defect.Title = "Testing from VS to TFS Bug";
Defect.Description = "Testing from VS to entered Bug in to TFS.";
Defect.Fields["Assigned To"].Value = "Test";
Defect.Save();
}
上面显示的代码工作正常。
但是使用 SQL Server 存储过程是否可以达到相同的结果?有没有办法连接到 TFS 并使用存储过程向 TFS 添加错误?
我有我的数据库,并且我想从 sql 存储过程连接到 TFS 并创建 WorkItem。通过 C# 我已经完成了上面的例子。但如果可以从存储过程中实现同样的效果,我需要任何示例。
Update:
您可以从 SQL CLR 调用 Web 服务。一些教程可能会有所帮助:
- 如何创建 SQL CLR 存储过程以从 Web 服务获取数据并将结果插入 SQL Server 表中 https://stackoverflow.com/questions/45536835/how-to-create-a-sql-clr-stored-procedure-to-get-data-from-a-web-service-and-inse
- 使用 Web 服务和 SQL Server 存储过程生成 JSON 数据 https://www.c-sharpcorner.com/article/generate-json-data-using-web-service-and-sql-server-stored-procedure/
不,唯一为用户查询而设计的数据库是仓库数据库。其他明确不支持,不应直接查询。
Do not 直接对 TFS 数据库进行任何更改,否则你可能失去支持来自微软。
请在这里看看这个类似的问题:向TFS数据库添加存储过程 https://social.msdn.microsoft.com/Forums/vstudio/en-US/59950845-afea-40e6-9f97-3cc1b0d63a76/add-a-stored-procedure-to-tfs-database?forum=tfsreporting
除了使用客户端 API 之外,您还可以使用 TFS 中的 Rest API 来执行某些操作。
工作项 - 创建 https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/create?view=azure-devops-server-rest-5.0
POST https://{instance}/{collection}/{project}/_apis/wit/workitems/${type}?api-version=5.0
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)