2017-06-13 42 views
2

我正在嘗試從命令行更新一些項目的nuget引用。這些項目使用包含PackageReference元素的新格式。我使用的命令是:使用新的csproj格式的nuget.exe更新

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 <Project> 
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更新包的命令行?

+0

你有什麼版本的nuget.exe? –

+0

nuget v 3.4.4.1321 – user653649

回答

2

您需要nuget.exe版本> = 4才能使用新的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 Studio\2017\Professional\MSBuild\15.0\bin'. 
Unable to update. The project does not contain a packages.config file. 

然而,你也許可以使用PowerShell的命令行開關

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

+0

這是我的理解,這個命令恢復包。我想將我的軟件包引用更新到最新版本。 – user653649

+0

對不起我的錯誤,如何使用PowerShell的'Update-Package' –

+0

我想過使用powershell的update-package,但是我找不到包含它的腳本。你能再詳細一點嗎? – user653649

2

目前,這是不可能的。請參閱this GitHub issue進行跟蹤。

用於添加引用的cli命令支持通過重新運行dotnet add package The.Package.Id來更新項目中的單個程序包。