Sometimes you want to update a read only system field in TFS, such as System.CreatedDate or System.ResolvedDate. There is no way to do that with TFS 2010 by using the UI or the object model because both of those methods execute validation rules and you can’t disable them. I heard that you can bypass them in TFS 2012 using the object model, but with TFS 2010 you have to use the WorkItemServer.Update method and pass in the values in an xml package with BypassRules set to true.
Most people will first try to set the property directly using the object model like this:
But you get the error: “The property ‘Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.CreatedDate’ has no setter” OR “Property or indexer ‘Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem.CreatedDate’ cannot be assigned to – it is read only”
Then you’ll try to bypass the build time error by setting the property using the Fields name value pair by doing something like this:
But you get the “InvalidNotOldValue” validation error when calling Validate() and “TF237124: Work Item is not ready to save”
So the only way to do this with TFS 2010 is to bypass the validation rules using the WorkItemServer.Update method. Here’s how you do that:
1. Add the following references to your project:
- c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll
- c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.WorkItemTracking.Client.dll
- c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.WorkItemTracking.Proxy.dll
2. Copy the following code into your project or take snippets to meet your needs. The inline comments explain what everything does.