VSTS Nuget 推送:400(错误请求)

VSTS Nuget push: 400 (Bad Request)

我正在尝试推送到 VSTS 的包部分。我收到了 Bad Request,但没有进一步的详细信息,这非常令人沮丧。这是我的请求和 return.

nuget push -Source "MFS" package.nupkg -Verbosity detailed -ApiKey VSTS

NuGet Version: 3.5.0.1938
Pushing package.nupkg to 'https://instance.pkgs.visualstudio.com/_packaging/c59817c1-a3c5-4654-95cf-760c1ce56c62/nuget/v2/'...
  PUT https://instance.pkgs.visualstudio.com/_packaging/c59817c1-a3c5-4654-95cf-760c1ce56c62/nuget/v2/
  BadRequest https://instance.pkgs.visualstudio.com/_packaging/c59817c1-a3c5-4654-95cf-760c1ce56c62/nuget/v2/ 10597ms
System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at NuGet.Protocol.Core.Types.PackageUpdateResource.<>c.<PushPackageToServer>b__19_1(HttpResponseMessage response)
   at NuGet.Protocol.HttpSource.<ProcessResponseAsync>d__14`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 NuGet.Protocol.Core.Types.PackageUpdateResource.<PushPackageToServer>d__19.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 NuGet.Protocol.Core.Types.PackageUpdateResource.<PushPackageCore>d__13.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 NuGet.Protocol.Core.Types.PackageUpdateResource.<PushPackage>d__12.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 NuGet.Protocol.Core.Types.PackageUpdateResource.<Push>d__8.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 NuGet.Commands.PushRunner.<Run>d__0.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 NuGet.CommandLine.PushCommand.<ExecuteCommandAsync>d__28.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at NuGet.CommandLine.Command.Execute()
   at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)
---> (Inner Exception #0) System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at NuGet.Protocol.Core.Types.PackageUpdateResource.<>c.<PushPackageToServer>b__19_1(HttpResponseMessage response)
   at NuGet.Protocol.HttpSource.<ProcessResponseAsync>d__14`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 NuGet.Protocol.Core.Types.PackageUpdateResource.<PushPackageToServer>d__19.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 NuGet.Protocol.Core.Types.PackageUpdateResource.<PushPackageCore>d__13.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 NuGet.Protocol.Core.Types.PackageUpdateResource.<PushPackage>d__12.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 NuGet.Protocol.Core.Types.PackageUpdateResource.<Push>d__8.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 NuGet.Commands.PushRunner.<Run>d__0.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 NuGet.CommandLine.PushCommand.<ExecuteCommandAsync>d__28.MoveNext()<---

系统提示我输入 username/password,我认为这是正确的。没有比这更进一步的数据:没有输出日志,没有事件日志,什么都没有。这就是我要继续的。

我尝试删除源代码并读取它,但系统没有提示我再次输入我的凭据,所以如果我的凭据有问题,它会缓存在某个地方,但我不知道在哪里。

TIA, 马特

您需要 -ApiKey {string} 例如-ApiKey VSTS 推。

改写以满足 Whosebug 回答政策:

我们看到推送的包无效,因为它不包含以 .nuspec 结尾的文件。您应该以 zip 文件形式打开 nupkg 并确认该包包含一个以 .nuspec 结尾的文件。

想通了。我在 nupkg 的根目录下有一个文件夹,所以我所有的文件实际上都在 2 层以下。一旦我将 nuspec 和其他文件带到根目录,它就起作用了。

TL;DR 始终添加 -ApiKey VSTS

我也终于弄明白了。

我省略了 ApiKey 因为我是用我的凭据进行身份验证的,所以我为什么需要密钥?而且我不知道我们公司 VSTS 的密钥。

正在显示警告,但我忽略了它,认为这是一个一般的本地 NuGet.exe 警告,当你在没有钥匙的情况下按下它时。

然后我灵机一动,实际上显示的警告是 header 值,它不知何故需要一个密钥,只是因为它需要。

因此,与一位同事一起查看 VSTS 提要说明本身,我们在他们的示例中看到 -ApiKey VSTS 并添加了它,但仍然需要登录,宾果游戏!