执行TfvcClient的CreateChangesetAsync时出现“方法不允许”异常

时间:2019-03-11 08:26:07

标签: c# .net .net-4.5 tfs2013

我在一个相当大的组织中工作,我们面临一个问题,因为我们需要迁移一个解决方案。

总而言之,我们有一个内部工具,可以浏览或安装旧的 TFS 2013 服务器并解析几个csproj和配置文件以更新其中的某些内容,以便能够将我们的网站迁移到 IIS10

先前的解决方案使用NuGet软件包 Machado.Microsoft.TeamFoundation Machado.Microsoft.TeamFoundation.client 现在已过时)并且不再运作良好。

决定将我们的解决方案迁移到“ Microsoft.TeamFoundation ” NuGet程序包。一切顺利,而不是签到部分。

private TfvcChangesetRef Checkin(TfvcItem item, string newContent)
{
    // Establish a connection using Windows Credentials
    using (var connection = TfsHelper.GetConnection())
    // Create TFS Client
    using (var tfvcClient = connection.GetClient<TfvcHttpClient>())
    {
        item.ContentMetadata = new FileContentMetadata();

        var changeset = new TfvcChangeset();
        var tfvcChange = new TfvcChange(item, versionControlChangeType.Edit);
        tfvcChange.NewContent = new ItemContent();
        tfvcChange.NewContent.Content = newContent;
        tfvcChange.NewContent.ContentType = ItemContentType.RawText;
        tfvcChange.Item.Path = item.Path;

        var changesList = new List<TfvcChange>();
        changesList.Add(tfvcChange);
        changeset.Author = new IdentityRef();
        changeset.Changes = changesList;
        changeset.Comment = "This is a test";

        return tfvcClient.CreateChangesetAsync(changeset).Result;
    }
}

TfsHelper.GetConnection()的定义是:

public static VssConnection GetConnection()
{
    var connection = new VssConnection(new Uri(ConfigurationManager.AppSettings["TfsUri"]), new VssAadCredential());

    connection.ConnectAsync().SyncResult();

    // Correctly contains the AAD user account
    return connection;
}

使用包含以下内容的变更集调用tfvcClient.CreateChangesetAsync(changeset)时,应用程序中断了:

Changes          Count = 1 (Correct, one change to be checked in)
Comment          "This is a test"
Author           typeof(IdentifyRef)
Other values     Default ones.

抛出的异常是:

System.AggregateException: 'One or more errors occurred.'
InnerException: VssServiceResponseException: Method Not Allowed

StackTrace of innerException:
   at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.<HandleResponseAsync>d__52.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.<SendAsync>d__50.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.<SendAsync>d__47`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.<SendAsync>d__28`1.MoveNext()

我们已经检查并实施了一些在Internet上找到的解决方案,但是目前没有任何效果。您对什么地方有问题或缺失有一个了解吗?

谢谢

1 个答案:

答案 0 :(得分:1)

在TFS 2013的ExtendedClient库中使用SOAP对象模型; TFS 2013不完全支持REST客户端使用的REST API。