tl;dr: Mount a cache into your container for downloaded NuGet packages, otherwise you'll have to download and compile your dependencies every time the build runs
dotnet stores downloaded NuGet packages in
~/.nuget/packages. However, because Batect destroys all of your containers once the task finishes,
this directory is lost at the end of every task run - which means that
dotnet will have to download all of your dependencies again next time you run the task,
significantly slowing down the build.
The solution to this is to mount a cache into the container at
~/.nuget/packages, so that these downloaded dependencies are
persisted between builds.
Note that you can't use
~ in the container path for a volume mount:
- If you're using run as current user mode, use the home directory you specified for
- If you're not using run as current user mode, use
/rootas the home directory, as the vast majority of containers default to the root user and use this as the root user's home directory.
The example configuration above demonstrates how to do this.
tl;dr: Mount a cache into your container the
obj directory for each project in your codebase, otherwise you'll experience poor performance on macOS and Windows,
and issues with some IDEs.
obj directory is used to store intermediate build output. However, when running on macOS and Windows,
Docker exhibits poor I/O performance for directories mounted from the macOS or Windows host, as discussed in the section on caches.
obj directory contains files that include the absolute path to the NuGet packages in your project, which are only correct in the context of the container.
These incorrect paths can cause issues for some IDEs (including Rider) that rely on these files to show code completion information for dependencies.