Sdk: dotnet restore --no-cache --force completes without error with no internet connection

Created on 19 Jul 2017  路  4Comments  路  Source: dotnet/sdk

This is with .NET Core 2.0 Preview 2 tooling. I'd expect --no-cache restores instructed to bypass cache to fail when no upstream sources are available...but that doesn't happen. Looking at procmon, it seems to be completely ignoring the --no-cache argument.

Here's what dotnet restore --no-cache --force registers during a run:
screen shot 2017-07-19 at 17 04 23

Steps to reproduce

  1. Download the MiniProfiler/dotnet repo
  2. Restore the solution
git clone [email protected]:MiniProfiler/dotnet.git
cd dotnet
dotnet restore
  1. Disconnect your internet (unplug a cable, turn on WiFi, disable the adapter...whatever)
  2. Try restoring the package again, disabling cache (--no-cache) and forced (--force)
dotnet restore --no-cache --force

Expected behavior

The restore would fail, unable to connect to any package sources and bypassing local cache.

Actual behavior

The restore succeeds without issue:

位 dotnet restore --no-cache --force
  Restoring packages for C:\Temp\dotnet\samples\Samples.AspNetCore\Samples.AspNetCore.csproj...
  Restoring packages for C:\Temp\dotnet\samples\Samples.Console\Samples.Console.csproj...
  Restoring packages for C:\Temp\dotnet\benchmarks\MiniProfiler.Benchmarks\MiniProfiler.Benchmarks.csproj...
  Restore completed in 156.69 ms for C:\Temp\dotnet\samples\Samples.Console\Samples.Console.csproj.
  Restoring packages for C:\Temp\dotnet\samples\Samples.Mvc5\Samples.Mvc5.csproj...
  Restore completed in 37.47 ms for C:\Temp\dotnet\samples\Samples.Mvc5\Samples.Mvc5.csproj.
  Restoring packages for C:\Temp\dotnet\src\MiniProfiler.AspNetCore.Mvc\MiniProfiler.AspNetCore.Mvc.csproj...
  Restore completed in 1.43 sec for C:\Temp\dotnet\benchmarks\MiniProfiler.Benchmarks\MiniProfiler.Benchmarks.csproj.
  Restoring packages for C:\Temp\dotnet\src\MiniProfiler.AspNetCore\MiniProfiler.AspNetCore.csproj...
  Restore completed in 1.27 sec for C:\Temp\dotnet\src\MiniProfiler.AspNetCore.Mvc\MiniProfiler.AspNetCore.Mvc.csproj.
  Restoring packages for C:\Temp\dotnet\src\MiniProfiler.EF6\MiniProfiler.EF6.csproj...
  Restore completed in 5.78 ms for C:\Temp\dotnet\src\MiniProfiler.EF6\MiniProfiler.EF6.csproj.
  Restoring packages for C:\Temp\dotnet\src\MiniProfiler.EntityFrameworkCore\MiniProfiler.EntityFrameworkCore.csproj...
  Restore completed in 402.71 ms for C:\Temp\dotnet\src\MiniProfiler.AspNetCore\MiniProfiler.AspNetCore.csproj.
  Restoring packages for C:\Temp\dotnet\src\MiniProfiler.Mvc5\MiniProfiler.Mvc5.csproj...
  Restore completed in 11.53 ms for C:\Temp\dotnet\src\MiniProfiler.Mvc5\MiniProfiler.Mvc5.csproj.
  Restoring packages for C:\Temp\dotnet\src\MiniProfiler.Providers.MySql\MiniProfiler.Providers.MySql.csproj...
  Restore completed in 420.85 ms for C:\Temp\dotnet\src\MiniProfiler.EntityFrameworkCore\MiniProfiler.EntityFrameworkCore.csproj.
  Restoring packages for C:\Temp\dotnet\src\MiniProfiler.Providers.RavenDB\MiniProfiler.Providers.RavenDB.csproj...
  Restore completed in 276.22 ms for C:\Temp\dotnet\src\MiniProfiler.Providers.MySql\MiniProfiler.Providers.MySql.csproj.
  Restoring packages for C:\Temp\dotnet\src\MiniProfiler.Providers.Redis\MiniProfiler.Providers.Redis.csproj...
  Restore completed in 2.23 sec for C:\Temp\dotnet\samples\Samples.AspNetCore\Samples.AspNetCore.csproj.
  Restoring packages for C:\Temp\dotnet\src\MiniProfiler.Providers.SqlServerCe\MiniProfiler.Providers.SqlServerCe.csproj...
  Restore completed in 9.2 ms for C:\Temp\dotnet\src\MiniProfiler.Providers.SqlServerCe\MiniProfiler.Providers.SqlServerCe.csproj.
  Restoring packages for C:\Temp\dotnet\src\MiniProfiler.Providers.SqlServer\MiniProfiler.Providers.SqlServer.csproj...
  Restore completed in 286.82 ms for C:\Temp\dotnet\src\MiniProfiler.Providers.RavenDB\MiniProfiler.Providers.RavenDB.csproj.
  Restoring packages for C:\Temp\dotnet\src\MiniProfiler.Shared\MiniProfiler.Shared.csproj...
  Restore completed in 196.94 ms for C:\Temp\dotnet\src\MiniProfiler.Providers.Redis\MiniProfiler.Providers.Redis.csproj.
  Restoring packages for C:\Temp\dotnet\src\MiniProfiler\MiniProfiler.csproj...
  Restore completed in 7.85 ms for C:\Temp\dotnet\src\MiniProfiler\MiniProfiler.csproj.
  Restoring packages for C:\Temp\dotnet\tests\MiniProfiler.Providers.RavenDB.Tests\MiniProfiler.Providers.RavenDB.Tests.csproj...
  Restore completed in 19.07 ms for C:\Temp\dotnet\tests\MiniProfiler.Providers.RavenDB.Tests\MiniProfiler.Providers.RavenDB.Tests.csproj.
  Restore completed in 223.15 ms for C:\Temp\dotnet\src\MiniProfiler.Providers.SqlServer\MiniProfiler.Providers.SqlServer.csproj.
  Restoring packages for C:\Temp\dotnet\tests\MiniProfiler.Tests\MiniProfiler.Tests.csproj...
  Restoring packages for C:\Temp\dotnet\tests\MiniProfiler.Providers.Redis.Tests\MiniProfiler.Profilers.Redis.Tests.csproj...
  Restore completed in 52.73 ms for C:\Temp\dotnet\tests\MiniProfiler.Tests\MiniProfiler.Tests.csproj.
  Restoring packages for C:\Temp\dotnet\src\MiniProfiler.Shared\MiniProfiler.Shared.csproj...
  Restore completed in 381.32 ms for C:\Temp\dotnet\src\MiniProfiler.Shared\MiniProfiler.Shared.csproj.
  Restoring packages for C:\Temp\dotnet\src\MiniProfiler.Shared\MiniProfiler.Shared.csproj...
  Restore completed in 416.19 ms for C:\Temp\dotnet\tests\MiniProfiler.Providers.Redis.Tests\MiniProfiler.Profilers.Redis.Tests.csproj.
  Restoring packages for C:\Temp\dotnet\tests\MiniProfiler.Tests\MiniProfiler.Tests.csproj...
  Restore completed in 695.44 ms for C:\Temp\dotnet\src\MiniProfiler.Shared\MiniProfiler.Shared.csproj.
  Restore completed in 606.9 ms for C:\Temp\dotnet\src\MiniProfiler.Shared\MiniProfiler.Shared.csproj.
  Restore completed in 590.48 ms for C:\Temp\dotnet\tests\MiniProfiler.Tests\MiniProfiler.Tests.csproj.

Environment data

dotnet --info output:

位 dotnet --info
.NET Command Line Tools (2.0.0-preview2-006497)

Product Information:
 Version:            2.0.0-preview2-006497
 Commit SHA-1 hash:  06a2093335

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.15063
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.0.0-preview2-006497\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0-preview2-25407-01
  Build    : 40c565230930ead58a50719c0ec799df77bddee9

/cc @rrelyea @emgarten

Most helpful comment

The global packages folder (.nuget\packages) is considered a source not a cache.

...this is pretty much the opposite of everything I've ever been told about .nuget. Many talks refer to it as the "local NuGet cache". Additionally, the current help says:

--no-cache                           Do not cache packages and http requests.

That, to me, means both of them, which is consistent with messaging elsewhere.

Why would I care about HTTP cache most of the time? The .nuget folder is what I want to bypass. Additionally, the workaround for doing a build and forcing a remote fetch should not be "hose every other build on the machine". Clearing the entire local cache is very much a nuclear option in terms of builds. The same would be true on a build server which often uses the same user.

I believe this behavior should change.

All 4 comments

The global packages folder (.nuget\packages) is considered a source not a cache.

--no-cache avoids using the http cache, if however the packages are already in the global folder then restore will not go online in the first place.

--force will cause the project to restore even if it hasn't changed. This skips the noop feature that has been added in CLI 2.0.0 for restore.

These flags aren't the most obvious, we're currently looking at improving this for NuGet. To force a restore to level you might be expecting here you would need to delete all packages and caches first, you can do this with: dotnet nuget locals --clear all

This issue was moved to NuGet/Home#5619

The global packages folder (.nuget\packages) is considered a source not a cache.

...this is pretty much the opposite of everything I've ever been told about .nuget. Many talks refer to it as the "local NuGet cache". Additionally, the current help says:

--no-cache                           Do not cache packages and http requests.

That, to me, means both of them, which is consistent with messaging elsewhere.

Why would I care about HTTP cache most of the time? The .nuget folder is what I want to bypass. Additionally, the workaround for doing a build and forcing a remote fetch should not be "hose every other build on the machine". Clearing the entire local cache is very much a nuclear option in terms of builds. The same would be true on a build server which often uses the same user.

I believe this behavior should change.

This is interesting to me for integration tests. I want to pull from a generated nuget.config test package source without either reading from or writing to any machine-wide state, especially .nuget\packages.

Was this page helpful?
0 / 5 - 0 ratings