nuget.exe update with new csproj format

 ̄綄美尐妖づ 提交于 2019-12-12 17:37:27

问题


I am trying to update the nuget references of some projects from the command line. These projects use the new format which include PackageReference elements. 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. 
If the project is authored in the MSBuild 2003 format, please add 
xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the <Project> 
element. If the project has been authored in the old 1.0 or 1.2 format, 
please convert it to MSBuild 2003 format.

Is there some way to use nuget.exe or dotnet.exe to update packages from the command line?


回答1:


You will need version >= 4 of nuget.exe to work with the new csproj format.

However you will still need to use the old style packages.config or you will get the following output

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

Update-Package

These can be run from the 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

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




回答2:


At the moment, this is not possible. See this GitHub issue for tracking.

The cli commands for adding references however support updating single packages in a project by re-running dotnet add package The.Package.Id.



来源:https://stackoverflow.com/questions/44528289/nuget-exe-update-with-new-csproj-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!