문제

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