首页 > 解决方案 > CreatePushAsync 不起作用:VssServiceException:提供的参数无效。参数名称:newPush

问题描述

我正在尝试复制文档中给出的发布请求:https ://docs.microsoft.com/en-us/rest/api/azure/devops/git/pushes/create?view=azure-devops-rest- 5.0#update_a_file

使用 .Net 库进行扩展。

我通过反复试验检查了 refUpdate 和 OldObjectId 是否正确。更改、项目、回购都已定义且不为空。

   GitPush push = new GitPush();
   GitCommit gitCommit = new GitCommit();
   GitChange change = new GitChange();
   ItemContent content = new ItemContent();
   content.Content = changeString;
   content.ContentType = ItemContentType.RawText;
   change.NewContent = new ItemContent();
   change.ChangeType = VersionControlChangeType.Edit;
   change.Item = item;
   List<GitChange> changes = new List<GitChange>();
   changes.Add(change);
   gitCommit.Changes = changes;
   gitCommit.Comment = "updated app.cpp";
   GitRefUpdate refUpdate = new GitRefUpdate();
   refUpdate.Name = "refs/heads/dev";
   refUpdate.OldObjectId = oldObjectId;
   List<GitCommit> commits = new List<GitCommit>();
   commits.Add(gitCommit);
   List<GitRefUpdate> refUpdates = new List<GitRefUpdate>();
   refUpdates.Add(refUpdate);
   push.Commits = commits;
   push.RefUpdates = refUpdates;
   GitPush pushed = gitClient.CreatePushAsync(push, repo.Id).Result;

在最后一行,调试器给出了参数“newPush”未定义的异常。

标签: c#restazure-devops

解决方案


推荐阅读