nuget.exe 使用新的 csproj 格式更新

nuget.exe update with new csproj format

我正在尝试从命令行更新某些项目的 nuget 引用。这些项目使用包含 PackageReference 元素的新格式。我使用的命令是:

nuget.exe update someproj.csproj

这会导致错误:

The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format.

有什么方法可以使用 nuget.exe 或 dotnet.exe 从命令行更新软件包吗?

您需要版本 >= 4 of nuget.exe 才能使用新的 csproj 格式。

但是您仍然需要使用旧样式 packages.config 否则您将得到以下输出

C:\dev>nuget.exe update test.csproj
MSBuild auto-detection: using msbuild version '15.1.548.43366' from 'C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild.0\bin'.
Unable to update. The project does not contain a packages.config file.

但是您可以使用 powershell commandlets

Update-Package

这些可以是来自包管理器控制台的 运行 (https://docs.microsoft.com/en-us/nuget/tools/package-manager-console)。

你也可以只加载powershell模块然后执行下面的命令

Import-Module PackageManagement.Cmdlets.dll 

Set-Project MySolution "MySolution.sln" 

Update-Package

有关此内容的更多信息,请访问此博客 - http://community.sharpdevelop.net/blogs/mattward/archive/2011/06/12/InstallingNuGetPackagesOutsideVisualStudio.aspx

目前,这是不可能的。请参阅 this GitHub issue 进行跟踪。

用于添加引用的 cli 命令但是支持通过重新更新项目中的单个包运行 dotnet add package The.Package.Id.