I believe this might be related to #2249
In that case I was unable to update at all due to an exception being thrown due to a failure to find the old package in my TeamCity feed (despite the fact that it was in fact in the feed). Now I'm using v3.5 compiled from sources today, and the same scenario does not in fact error out, but also does not correctly update the project file.
Before the update the .csproj looks like this:
<Import Project="..\packages\Blah.0.1.0-pre23\build\Blah.targets" Condition="Exists('..\packages\Blah.0.1.0-pre23\build\Blah.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Blah.0.1.0-pre23\build\Blah.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Blah.0.1.0-pre23\build\Blah.targets'))" />
</Target>
and the console logs this:
Scanning for projects...
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
Found 5 projects with a packages.config file. (MyProject.csproj)
Looking for installed packages in 'packages'.
Feeds used:
http://teamcity.local/guestAuth/app/nuget/v1/FeedService.svc
Attempting to gather dependency information for multiple packages with respect to project 'C:\dev\Solution\MyProject\MyProject.csproj', targeting '.NETFramework,Version=v4.5.1'
Attempting to resolve dependencies for multiple packages.
Resolving actions install multiple packages
GET https://teamcity.local/guestAuth/app/nuget/v1/FeedService.svc/Packages(Id='Blah',Version='0.1.0-pre24')
OK https://teamcity.local/guestAuth/app/nuget/v1/FeedService.svc/Packages(Id='Blah',Version='0.1.0-pre24') 59ms
For adding package 'Blah.0.1.0-pre24' to project 'MyProject.csproj' that targets 'net451'.
For adding package 'Blah.0.1.0-pre24' to project 'MyProject.csproj' that targets 'net451'.
Package 'Blah.0.1.0-pre24' already exists in folder 'C:\dev\Solution\packages'
Added package 'Blah.0.1.0-pre24' to 'packages.config'
Successfully installed 'Blah 0.1.0-pre24' to MyProject.csproj
After the update it looks like this:
<Import Project="..\packages\Blah.0.1.0-pre23\build\Blah.targets" Condition="Exists('..\packages\Blah.0.1.0-pre23\build\Blah.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Blah.0.1.0-pre23\build\Blah.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Blah.0.1.0-pre23\build\Blah.targets'))" />
<Error Condition="!Exists('..\packages\Blah.0.1.0-pre24\build\Blah.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Blah.0.1.0-pre24\build\Blah.targets'))" />
</Target>
<Import Project="..\packages\Blah.0.1.0-pre24\build\Blah.targets" Condition="Exists('..\packages\Blah.0.1.0-pre24\build\Blah.targets')" />
Note that if I update from Visual Studio, the project updates correctly, and the Output window reports:
Attempting to gather dependency information for multiple packages with respect to project 'MyProject', targeting '.NETFramework,Version=v4.5.1'
Attempting to resolve dependencies for multiple packages.
Resolving actions install multiple packages
Removed package 'Blah 0.1.0-pre23' from 'packages.config'
Successfully uninstalled 'Blah 0.1.0-pre23' from MyProject
GET https://teamcity.local/guestAuth/app/nuget/v1/FeedService.svc/Packages(Id='Blah',Version='0.1.0-pre24')
OK https://teamcity.local/guestAuth/app/nuget/v1/FeedService.svc/Packages(Id='Blah',Version='0.1.0-pre24') 14ms
Package 'Blah.0.1.0-pre24' already exists in folder 'C:\dev\Solution\.nuget\..\packages'
Added package 'Blah.0.1.0-pre24' to 'packages.config'
Successfully installed 'Blah 0.1.0-pre24' to MyProject
Removing package 'Blah 0.1.0-pre23' from folder 'C:\dev\Solution\.nuget\..\packages'
Removed package 'Blah 0.1.0-pre23' from folder 'C:\dev\Solution\.nuget\..\packages'
========== Finished ==========
This looks like a bug that needs to be fixed in nuget.exe
If you would like to work around this the best way is to switch your project over to use project.json instead of packages.config. project.json supports updating from the command line and floating versions.
@emgarten: I'm not familiar with the project.json format. Any quick pointers on how I would convert all of my existing packages.config files?
@wbradney this is not officially supported yet, but we will support project.json for all projects in the future.
@emgarten: Thanks - great link. I have a _lot_ of projects so I may try to script the conversion. The two project types we care about right now are .csproj and .vcxproj, so I hope it works for those. I assume that it's also OK to mix the two approaches within a solution?
Is the packages.config approach going to be deprecated?
I actually seem to be having trouble with project.json in native/CLI projects. Is this supposed to be supported?
project.json is not supported for native yet
Ah, that kind of kills my plans then, I think. A shame, because I was actually enjoying the advantages over packages.config.
Any ETA for native support?
This problem still exists in NuGet 3.5.0!
EDIT: This is an extremely annoying bug, because this affects all packages supporting C++/CLI.
Any news on this issue?
Sorry, none yet. It is in the future-1 milestone, which means we cannot afford to look at right now.
In general, also, we are working hard to enable a new PackageReferences model which builds on top of UWP-style project.json to solve problems such as these.
FYI: This is not only for C++.
Also, there seems to be a pull request fixing this: https://github.com/NuGet/NuGet.Client/pull/1248
Most helpful comment
Ah, that kind of kills my plans then, I think. A shame, because I was actually enjoying the advantages over packages.config.
Any ETA for native support?