質問

I already know WorkItem.Validate method can get an ArrayList of fields in this work item that are not valid(msdn).

But they do seem to contain only invalid fields and thus names, but not contain any error messages, i.e. why they're invalid, which is useful for situation of submitting workitem without using the built in TFS controls.
How to get error tip like "new bug 1: TF200012: field 'Title' cannot be empty."?

For better understanding, please see the picture.msdn
I am using VS2010 SP1 Chinese language, and the error discription is translated as above.

役に立ちましたか?

解決

Visual Studio is just another client that wraps TFS error messages. You can't capture the TF* errors but you can get the FieldStatus and print you own message.

var invalidFields = workItem.Validate();
if (invalidFields.Count > 0)
{
    foreach (Field field in invalidFields)
    {
        string errorMessage = string.Empty;
        if (field.Status == FieldStatus.InvalidEmpty)
        {
            errorMessage = string.Format("{0} {1} {2}: TF20012: field \"{3}\" cannot be empty."
                , field.WorkItem.State
                , field.WorkItem.Type.Name
                , field.WorkItem.TemporaryId
                , field.Name);
        }
        //... more handling here

        Console.WriteLine(errorMessage);
    }
}
else // Validation passed
{
    workItem.Save();
}

他のヒント

field.Status.ToString()

Worked for me, this will capture the error message.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top