Nuget发布错误:无法处理请求。 '客户端版本' 4.1.0'

时间:2018-01-28 06:17:56

标签: visual-studio nuget visual-studio-2017 nuget-package

我正在发布NuGet包。我安装了最新版本的Visual Studio 2017社区。我收到以下错误:

  

无法处理请求。 '客户端版本' 4.1.0'或更高   要求能够推包。请联系support@nuget.org   获得更多细节。'。

为什么最新的Visual Studio无法发布NuGet?怎么解决?完整的构建日志如下:

1>------ Rebuild All started: Project: MyProject.NuGet, Configuration: Release Any CPU ------
1>  MyProject.NuGet -> C:\Users\User\Documents\MyProject\MyProject.NuGet\bin\Release\MyProject.NuGet.dll
1>   
1>  NuGet Packager 2.0.3
1>   
1>  Creating backup...
1>  Renamed MyProject.1.0.6.nupkg to MyProject.1.0.6.nupkg.bak
1>   
1>  Updating NuGet...
1>  The element 'metadata' in namespace 'http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd' has invalid child element 'developmentDependency' in namespace 'http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd'. List of possible elements expected: 'releaseNotes, projectUrl, title, language, iconUrl, dependencies, frameworkAssemblies, tags, references, licenseUrl, summary, copyright, description' in namespace 'http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd'.
1>  Checking for updates from https://nuget.org/api/v2/.
1>  Currently running NuGet.exe 2.2.0.
1>  Updating NuGet.exe to 4.4.1.
1>   
1>  Creating package...
1>  Attempting to build package from 'Package.nuspec'.
1>  Id: MyProject
1>  Version: 1.0.6
1>  Authors: Boris Zinchenko
1>  Description: MyProject
1>  License Url: MyProject
1>  Project Url: MyProject
1>  Tags: MyProject
1>  Dependencies: 
1>  Added file 'lib\net20\MyProject.dll'.
1>  Added file 'tools\init.ps1'.
1>  Added file 'tools\install.ps1'.
1>  Added file 'tools\uninstall.ps1'.
1>  Successfully created package 'MyProject.1.0.6.nupkg'.
1>   
1>  Publishing package...
1>  Repository Url: https://www.nuget.org
1>   
1>  Pushing MyProject 1.0.6 to the NuGet gallery (https://www.nuget.org)...
1>  Failed to process request. 'A client version '4.1.0' or higher is required to be able to push packages. Please contact support@nuget.org to get more details.'. 
1>EXEC : The remote server returned an warning : (400) Bad Request..
1>  Pushing MyProject 1.0.6 to the NuGet gallery (https://www.nuget.org)...
1>  Failed to process request. 'A client version '4.1.0' or higher is required to be able to push packages. Please contact support@nuget.org to get more details.'. 
1>EXEC : The remote server returned an warning : (400) Bad Request..
1>   
1>  Exit Code: 0
1>   
1>  Build Exit Code: -1
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

更新

经过@Alexei Levenkov的宝贵建议后,我使用命令Install-Package NuGet.VisualStudio更新了NuGet版本。令人惊讶的是,它没有对我的错误产生任何影响,错误仍然保持不变。 NuGet控制台的更新日志如下所示。

Package Manager Console Host Version 4.5.0.4685
Type 'get-help NuGet' to see all available NuGet commands.

PM> Install-Package NuGet.VisualStudio

Attempting to gather dependency information for package 'NuGet.VisualStudio.4.5.0' with respect to project 'MyProject', targeting '.NETFramework,Version=v2.0'
Gathering dependency information took 20.7 ms
Attempting to resolve dependencies for package 'NuGet.VisualStudio.4.5.0' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'NuGet.VisualStudio.4.5.0'
Resolved actions to install package 'NuGet.VisualStudio.4.5.0'
Retrieving package 'NuGet.VisualStudio 4.5.0' from 'nuget.org'.
  GET https://api.nuget.org/v3-flatcontainer/nuget.visualstudio/4.5.0/nuget.visualstudio.4.5.0.nupkg
  OK https://api.nuget.org/v3-flatcontainer/nuget.visualstudio/4.5.0/nuget.visualstudio.4.5.0.nupkg 524ms
Installing NuGet.VisualStudio 4.5.0.
Adding package 'NuGet.VisualStudio.4.5.0' to folder 'C:\Users\User\Documents\MyProject\packages'
Added package 'NuGet.VisualStudio.4.5.0' to folder 'C:\Users\User\Documents\MyProject\packages'
Added package 'NuGet.VisualStudio.4.5.0' to 'packages.config'
Successfully installed 'NuGet.VisualStudio 4.5.0' to MyProject
Executing nuget actions took 5.01 sec
Time Elapsed: 00:00:07.1699206

3 个答案:

答案 0 :(得分:1)

看起来你没有获得NuGet的更新版本。我假设VS附带的一个小于4.1,听起来像www.nuget.org现在需要更高的版本。

更新NuGet:

答案 1 :(得分:1)

花了几个小时并且对所有标准的NuGet建议绝望之后,我在项目文件夹中发现了旧的NuGet.exe 2.2.0。为什么exe文件与NuGet部署代码一起安装和存储,以及为什么这个文件没有自动更新为这个项目的NuGet.VisualStudio安装,我不知道。可能是NuGet bug或NuGet.VisualStudio错误。

无论NuGet.exe没有自动更新的原因是什么,我从NuGet.org网站下载了最新的NuGet.exe,并在我的项目中手动替换了它。在本手册更换后,所有维修成功并成功发布。

因为我之前使用过标准的Microsoft项目模板进行NuGet发布,现在以标准方式升级到新的Visual Studio,我确信我走了一条共同的路线,许多其他人可能会重复这一路线以证明同样的问题。我认为Visual Studio团队必须承认它是一个bug并设计一个补丁。

答案 2 :(得分:1)

对于那些根据尝试将Powershell模块发布到PSGallery时遇到的错误消息通过搜索到达此处的用户,请尝试以下步骤。

# This should get you the current version of PowershellGet
Install-Module -Name PowerShellGet -Force -Scope AllUsers

# But just in case...
Update-Module -Name PowerShellGet -Force

打开一个新会话。

Import-Module PowershellGet -Force

# Make sure you have the expected version of the module
Get-Module PowershellGet

# Run your publish commands again 
<YOUR_PUBLISH_COMMAND>

其中某些步骤可能是不必要的,但这就是我在计算机上解决问题的方式。

如果您发现自己正在CI / CD管道中解决此问题,则可能需要添加一个步骤来为build-agent用户(或等效用户)安装模块。即使在为所有用户安装PowershellGet之后,我也必须这样做。

这是相关的博客文章:https://p0w3rsh3ll.wordpress.com/2019/03/01/quick-update-on-psgallery-publishing/