简体   繁体   English

nuget.exe 更新为新的 csproj 格式

[英]nuget.exe update with new csproj format

I am trying to update the nuget references of some projects from the command line.我正在尝试从命令行更新某些项目的 nuget 引用。 These projects use the new format which include PackageReference elements.这些项目使用包含 PackageReference 元素的新格式。 The command I am using is:我使用的命令是:

nuget.exe update someproj.csproj

This results in an error:这会导致错误:

The default XML namespace of the project must be the MSBuild XML namespace.项目的默认 XML 命名空间必须是 MSBuild XML 命名空间。 If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the element.如果项目是以 MSBuild 2003 格式创作的,请将 xmlns="http://schemas.microsoft.com/developer/msbuild/2003" 添加到元素中。 If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format.如果项目是用旧的 1.0 或 1.2 格式创作的,请将其转换为 MSBuild 2003 格式。

Is there some way to use nuget.exe or dotnet.exe to update packages from the command line?有没有办法使用 nuget.exe 或 dotnet.exe 从命令行更新包?

You will need version >= 4 of nuget.exe to work with the new csproj format.您将需要 nuget.exe 版本 >= 4 才能使用新的 csproj 格式。

However you will still need to use the old style packages.config or you will get the following output但是您仍然需要使用旧样式的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 Studio\2017\Professional\MSBuild\15.0\bin'.
Unable to update. The project does not contain a packages.config file.

However you might be able to use the powershell commandlets但是,您也许可以使用 powershell commandlet

Update-Package

These can be run from the package manager console ( https://docs.microsoft.com/en-us/nuget/tools/package-manager-console ).这些可以从包管理器控制台 ( https://docs.microsoft.com/en-us/nuget/tools/package-manager-console ) 运行。

You can also just load in the powershell module and execute the following您也可以只加载 powershell 模块并执行以下操作

Import-Module PackageManagement.Cmdlets.dll 

Set-Project MySolution "MySolution.sln" 

Update-Package

more information on this can be found on this blog - http://community.sharpdevelop.net/blogs/mattward/archive/2011/06/12/InstallingNuGetPackagesOutsideVisualStudio.aspx更多信息可以在这个博客上找到 - http://community.sharpdevelop.net/blogs/mattward/archive/2011/06/12/InstallingNuGetPackagesOutsideVisualStudio.aspx

At the moment, this is not possible.目前,这是不可能的。 See this GitHub issue for tracking.请参阅此 GitHub 问题以进行跟踪。

The cli commands for adding references however support updating single packages in a project by re-running dotnet add package The.Package.Id .但是,用于添加引用的 cli 命令支持通过重新运行dotnet add package The.Package.Id更新项目中的单个包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM