I have a WebApplication that creates and changes WorkItems through the API. I want the "ChangedBy" field be set to a specific string-value. This worked well with TFS 2013.
After upgrading to TFS 2015 my value is ignored and ChangedBy is always set to the identity of the user that I use for connecting to the TFS.
This is my code:
//Set some values on the WorkItem
item.Fields["ChangedBy"].Value = "MyUserName";
item.Save();
Is there a way to enforce the behaviour like it was in TFS 2013?
根据这一博客 ,默认情况下,更改者域是不可编辑的字段(由系统设置)中的一个。 为了改变它,你需要在BypassRule模式下使用工作,WorkItemStore对象。 绕过规则允许你修改工作项目领域没有任何限制,所以你可以改变的改变字段中。
定义你的代码:
TfsTeamProjectCollection tfctc = new TfsTeamProjectCollection(new Uri("http://servername:8080/tfs/DefaultCollection"));
WorkItemStore workItemStore = new WorkItemStore(tfctc, WorkItemStoreFlags.BypassRules);
WorkItem workItem = workItemStore.GetWorkItem(workitemid);
string changedBy = (string)workItem.Fields["Changed By"].Value;
workItem.Fields["Changed By"].Value = "User Name";