Nuget restore and caching

Morten Maxild's Avatar

Morten Maxild

25 Sep, 2018 03:42 PM

After migration from packages.config to PackageReference where nuget uses a global cache how can I best speed of restore times for builds

I was thinking about putting this in my ```apveyor.yml``` file

```
# cache the nuget packages folders (PROBLEM: The project.lock.json files are renamed and moved to obj\project.assets.json)
cache:
- '%USERPROFILE%\.nuget\packages' # global‑packages
- '%LocalAppData%\NuGet\v3-cache' # http‑cache

```

  1. Support Staff 1 Posted by Owen McDonnell on 25 Sep, 2018 05:22 PM

    Owen McDonnell's Avatar

    Are you saying that you are checking the project.lock.json files into source control? If you are using PackageReference, it's my understanding that you can just ignore the lock file.

  2. 2 Posted by Morten Maxild on 26 Sep, 2018 10:57 AM

    Morten Maxild's Avatar

    project.lock.json is dead. In .NET Core today the dotnet cli outputs obj/project.assets.json, but these files cannot be tracked by GIT, or used in cache expressions in appveyor.yml.

    I am using PackageReference in old csproj and also the new SDK csproj (also beased on PackageReference nuget model). Both use the global cache, as described above.

    Your documentation about caching nuget packages, only describe the old packages.config Nuget model. That is why I am asking for the best way to speed up nuget restore times on the build, if not using packages.config

  3. Support Staff 3 Posted by Owen McDonnell on 27 Sep, 2018 04:11 AM

    Owen McDonnell's Avatar

    So your question is what to use as a cache dependency? What about the project file that contains the PackageReference node?

  4. 4 Posted by Morten Maxild on 01 Oct, 2018 12:45 PM

    Morten Maxild's Avatar

    Can I cache the nuget global cache (%USERPROFILE%\.nuget\packages) outside the downloaded/cloned code tree?

  5. Support Staff 5 Posted by Owen McDonnell on 01 Oct, 2018 04:10 PM

    Owen McDonnell's Avatar

    I agree with your answer in this thread that it doesn't make sense to declare a cache dependency on the nuget global cache folder/tree. I was simply trying to answer the question I thought you were asking ("these files cannot be... used in cache expressions in appveyor.yml").

    Sure you can cache folders outside the clone directory.

  6. Ilya Finkelshteyn closed this discussion on 01 Dec, 2018 09:00 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac