Reputation: 11305
I would like to configure CI in Appveyor for a .net project and I am struggling with following errors:
error NU1403: Package content hash validation failed for System.Collections.NonGeneric.4.3.0. The package is different than the last restore.
Every project restore happens to throw similar thing
There was similar question and one advice was to clear nuget cache.
Whats the best course of action here?
Thanks
Directory.Build.props
<PropertyGroup>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
</PropertyGroup>
Build started
git config --global core.autocrlf true
git clone -q --branch=master https://github.com/User/App.git C:\projects\App
git checkout -qf 7066b969dd7564c573fb5e30fa6600a86c48644f
choco install opencover.portable
Chocolatey v0.11.3
Installing the following packages:
opencover.portable
By installing, you accept licenses for the packages.
Progress: Downloading opencover.portable 4.7.1221... 100%
opencover.portable v4.7.1221 [Approved]
opencover.portable package files install completed. Performing other installation steps.
Downloading opencover.portable
from 'https://github.com/OpenCover/opencover/releases/download/4.7.1221/opencover.4.7.1221.zip'
Progress: 100% - Completed download of C:\Users\appveyor\AppData\Local\Temp\1\chocolatey\opencover.portable\4.7.1221\opencover.4.7.1221.zip (7.76 MB).
Download of opencover.4.7.1221.zip (7.76 MB) completed.
Hashes match.
Extracting C:\Users\appveyor\AppData\Local\Temp\1\chocolatey\opencover.portable\4.7.1221\opencover.4.7.1221.zip to C:\ProgramData\chocolatey\lib\opencover.portable\tools...
C:\ProgramData\chocolatey\lib\opencover.portable\tools
ShimGen has successfully created a shim for OpenCover.Console.exe
ShimGen has successfully created a shim for OpenCover.Simple.Target.exe
ShimGen has successfully created a shim for OpenCover.Simple.Target.exe
The install of opencover.portable was successful.
Software installed to 'C:\ProgramData\chocolatey\lib\opencover.portable\tools'
Chocolatey installed 1/1 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Did you know the proceeds of Pro (and some proceeds from other
licensed editions) go into bettering the community infrastructure?
Your support ensures an active community, keeps Chocolatey tip-top,
plus it nets you some awesome features!
https://chocolatey.org/compare
choco install codecov
Chocolatey v0.11.3
Installing the following packages:
codecov
By installing, you accept licenses for the packages.
Progress: Downloading codecov 1.13.0... 100%
codecov v1.13.0 [Approved]
codecov package files install completed. Performing other installation steps.
Extracting 64-bit C:\ProgramData\chocolatey\lib\codecov\tools/codecov-win7-x64.zip to C:\ProgramData\chocolatey\lib\codecov\tools...
C:\ProgramData\chocolatey\lib\codecov\tools
ShimGen has successfully created a shim for codecov.exe
The install of codecov was successful.
Software installed to 'C:\ProgramData\chocolatey\lib\codecov\tools'
Chocolatey installed 1/1 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
dotnet --version
5.0.403
dotnet restore
Determining projects to restore...
C:\projects\App\Tests\Common.Tests\Common.Tests.csproj : error NU1403: Package content hash validation failed for System.Collections.NonGeneric.4.3.0. The package is different than the last restore. [C:\projects\App\App.sln]
appveyor.xml
version: '1.0.{build}'
image: Visual Studio 2019
branches:
only:
- master
init:
- cmd: git config --global core.autocrlf true
install:
before_build:
- choco install opencover.portable
- choco install codecov
- cmd: dotnet --version
- cmd: dotnet restore
build_script:
- cmd: dotnet build --configuration Release --no-restore
test_script:
- cmd: dotnet test --configuration Release --no-build --no-restore --verbosity minimal --test-adapter-path:. --logger:Appveyor /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:MergeWith="../TestResults/coverage.json" /p:CoverletOutputFormat=lcov
cache:
- '%USERPROFILE%\.nuget\packages -> **\project.json'
- C:\ProgramData\chocolatey\bin -> appveyor.yml
- C:\ProgramData\chocolatey\lib -> appveyor.yml
deploy: off
Upvotes: 5
Views: 1641
Reputation: 3342
short and simple:
dotnet restore --force-evaluate
Forces restore to reevaluate all dependencies even if a lock file already exists.
Upvotes: 4
Reputation: 11305
At Feodor suggestion I added powershell script which removes package.lock.json
files and it worked.
before_build:
- choco install opencover.portable
- choco install codecov
- ps: >-
Get-ChildItem .\ -include packages.lock.json -Recurse | foreach ($_) { remove-item $_.fullname -Force }
- cmd: dotnet --version
- cmd: dotnet restore
Upvotes: 0