NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

NuGet.exe damages project files during update command #6680

Open oalukin opened 6 years ago

oalukin commented 6 years ago

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe): NuGet.exe

NuGet version (x.x.x.xxx): 4.5.1.4879

OS version (i.e. win10 v1607 (14393.321)): win7 SP2, win10 v1709

Worked before? If so, with which NuGet version: bug exists in 3.5.0.1996, was not able to test on earlier versions

NuGet.exe update command breaks project files in the following cases:

Detailed repro steps so we can see the same problem

Use attached project UpdateBugTestClient to reproduce, issue happens on any package with content files

  1. Update package with the following command: nuget.exe update UpdateBugTestClient.sln -Id UpdateBugTestPackage -Version 1.1.0 -FileConflictAction Ignore

  2. Content file UpdateBugTestPackage.dll.config is deleted, project is damaged and cannot be built

  3. Update package with the following command: nuget.exe update UpdateBugTestClient.sln -Id UpdateBugTestPackage -Version 1.2.0

  4. Content file UpdateBugTestPackage.dll.config is deleted as expected but reference is left in project file, project is damaged and cannot be built

Other suggested things

As far as I can see in source code of NuGet.exe, uninstall package action for command line version has incorrect implementation, it simply deletes content file on disk but does not remove the reference from project file. That is the root cause for both issues.

Verbose Logs

nuget.exe update UpdateBugTestClient.sln -Id UpdateBugTestPackage -Version 1.1.0 -FileConflictAction Ignore -Verbosity detailed

NuGet Version: 4.5.1.4879
Scanning for projects...
MSBuild auto-detection: using msbuild version '15.6.82.30579' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
Found 1 project with a packages.config file. (UpdateBugTestClient.csproj)
Looking for installed packages in 'packages'.
Feeds used:
http://xxxxxxxxxxxxxxxxxx.com/api/v2
https://www.nuget.org/api/v2/
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

Attempting to gather dependency information for multiple packages with respect to project 'D:\Visual Studio\Projects\NuGetUpdateBug\UpdateBugTestClient\UpdateBu gTestClient\UpdateBugTestClient.csproj', targeting '.NETFramework,Version=v4.6.1'
Missing C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\updatebugtestpackage\1.1.0\updatebugtestpackage.1.1.0.nupkg
GET http://xxxxxxxxxxxxxxxxxx.com/api/v2/Packages(Id='UpdateBugTestPackage',Version='1.1.0')
GET https://www.nuget.org/api/v2/Packages(Id='UpdateBugTestPackage',Version='1.1.0')
OK http://xxxxxxxxxxxxxxxxxx.com/api/v2/Packages(Id='UpdateBugTestPackage',Version='1.1.0') 85ms
NotFound https://www.nuget.org/api/v2/Packages(Id='UpdateBugTestPackage',Version='1.1.0') 165ms
GET https://www.nuget.org/api/v2/FindPackagesById()?id='UpdateBugTestPackage'&semVerLevel=2.0.0
OK https://www.nuget.org/api/v2/FindPackagesById()?id='UpdateBugTestPackage'&semVerLevel=2.0.0 190ms
Total number of results gathered : 3
Gathering dependency information took 1.79 sec
Summary of time taken to gather dependencies per source :
https://www.nuget.org/api/v2/ - 395.01 ms
http://xxxxxxxxxxxxxxxxxx.com/api/v2 - 200.48 ms
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\ - 17.2 ms
Attempting to resolve dependencies for multiple packages.
Resolving dependency information took 0 ms
Resolving actions install multiple packages
Retrieving package 'UpdateBugTestPackage 1.1.0' from 'ABFX Nuget'.
GET http://xxxxxxxxxxxxxxxxxx.com/api/v2/Packages(Id='UpdateBugTestPackage',Version='1.1.0')
Removed package 'UpdateBugTestPackage 1.0.0' from 'packages.config'
Removed file 'packages.config' from folder 'D:\Visual Studio\Projects\NuGetUpdateBug\UpdateBugTestClient\UpdateBugTestClient'.
OK http://xxxxxxxxxxxxxxxxxx.com/api/v2/Packages(Id='UpdateBugTestPackage',Version='1.1.0') 80ms
Removed file 'UpdateBugTestPackage.dll.config' from folder 'D:\Visual Studio\Projects\NuGetUpdateBug\UpdateBugTestClient\UpdateBugTestClient'.
Successfully uninstalled 'UpdateBugTestPackage 1.0.0' from UpdateBugTestClient.csproj
For adding package 'UpdateBugTestPackage.1.1.0' to project 'UpdateBugTestClient.csproj' that targets 'net461'.
For adding package 'UpdateBugTestPackage.1.1.0' to project 'UpdateBugTestClient.csproj' that targets 'net461'.
Adding package 'UpdateBugTestPackage.1.1.0' to folder 'D:\Visual Studio\Projects\NuGetUpdateBug\UpdateBugTestClient\packages'
Added package 'UpdateBugTestPackage.1.1.0' to folder 'D:\Visual Studio\Projects\NuGetUpdateBug\UpdateBugTestClient\packages'
Added package 'UpdateBugTestPackage.1.1.0' to folder 'D:\Visual Studio\Projects\NuGetUpdateBug\UpdateBugTestClient\packages' from source 'http://xxxxxxxxxxxxxxxxxx.com/api/v2'
WARNING: 'UpdateBugTestPackage.dll.config' already exists. Skipping...
Added package 'UpdateBugTestPackage.1.1.0' to 'packages.config'
Successfully installed 'UpdateBugTestPackage 1.1.0' to UpdateBugTestClient.csproj
Executing nuget actions took 603.29 ms

Sample Project

NuGetUpdateBug.zip

Shazwazza commented 4 years ago

I have the same/similar issue. Running nuget.exe update with -FileConflictAction Ignore or IgnoreAll will delete any file that were including in the ~/Content folder of the nupkg package that has been changed. They will not be re-added, they are not ignored if they are changed, they are just removed. Setting the -FileConflictAction to Overwrite does overwrite them but then the user's changes are lost. My log output shows that it detects the file conflicts but these files are still removed which i think might actually happen early in the update phase when the original package version is removed.

This is using the legacy project/packaging with packages.config. The strange thing is that this operation works fine within Visual Studio. It just doesn't behave the same with nuget.exe. If anyone can tell me how to ensure the same behavior from cmd line as VS that would solve my problem. Perhaps I need to use an older version of nuget?

This is using vLatest as of last week: 5.5.1.6542