Azure Devops GitHttpClient的CreateAnnotatedTagAsync API失败

问题描述

调用GitHttpClient.CreateAnnotatedTagAsync时,即使我的凭据有效,我仍然收到“ VS30063:您无权访问https://dev.azure.com”。

这是我的代码

    var vssConnection = new VssConnection(new Uri("ORG_URI"),new VssBasicCredential(string.Empty,"PAT"));

    var gitClient = vssConnection.GetClient<GitHttpClient>();

    var tag = new GitAnnotatedTag
    {
        Name = "tagname",Message = "A new tag",TaggedBy = new GitUserDate
        {
            Name = "Name",Email = "Email",Date = DateTime.Now,ImageUrl = null
        },ObjectId = "SHA",Taggedobject = new GitObject
        {
            ObjectId = "SHA",ObjectType = GitObjectType.Commit
        },Url = string.Empty
    };

    var sourceRepo = await gitClient.GetRepositoryAsync("PROJECT",repoName);

    // This call works
    var tags = await gitClient.GetTagRefsAsync(sourceRepo.Id);

    // The tag is printed to the console
    Console.WriteLine(tags.First().Name);

   // This throws "VS30063: You are not authorized to access https://dev.azure.com"
   await gitClient.CreateAnnotatedTagAsync(tag,"PROJECT",sourceRepo.Id);
@H_502_6@

解决方法

您的PAT令牌有问题。我刚刚使用您的代码和具有完全访问权限的PAT创建了标签:

enter image description here

您可以创建一个新令牌并重试吗?