2

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 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?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
user653649
  • 115
  • 1
  • 9

2 Answers2

3

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.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
2

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://learn.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

Kevin Smith
  • 13,746
  • 4
  • 52
  • 77
  • It's my understanding that this command restores packages. I want to update my package references to the latest. – user653649 Jun 13 '17 at 18:10
  • Sorry my mistake, how about trying it using powershell `Update-Package` – Kevin Smith Jun 13 '17 at 18:19
  • I thought about using update-package from powershell, but I couldn't find a script that contains that. Could you elaborate a bit more? – user653649 Jun 13 '17 at 18:22
  • @user653649 Have you updated your NuGet version as Kevin has said? Above you say you are on 3.4.4 and not v4. Although the NuGet site says v4 is in the Visual Studio 2017 installer - I found this not to be the case at the time of my installation and so I had to download manually. – ColinM Jun 13 '17 at 18:36
  • I've updated the answer regarding the versioning, v4 supports the new format but only works with `packages.config` – Kevin Smith Jun 13 '17 at 18:39
  • The "new csproj" format however doesn't work with `packages.config` as its targets assume package reference style nuget management – Martin Ullrich Jun 13 '17 at 19:33