dotnet-subset
is a .NET tool that copies a subset of files from a repository to a directory.
The tool is mainly used in Dockerfiles to optimize the docker build caching for "dotnet restore" instructions.
To learn more about the motivation behind dotnet-subset
, please read the related blog post.
dotnet tool install --global dotnet-subset
Prerequisite: .NET SDK 6
- Clone this repository
- Open a terminal in the repository's root
dotnet pack --configuration Release
dotnet tool install dotnet-subset --global --add-source ./artifacts/Release/nupkg/dotnet-subset/
Description:
Create a subset for the restore operation.
Usage:
dotnet-subset restore <projectOrSolution> [options]
Arguments:
<projectOrSolution> Project or solution to restore.
Options:
--root-directory <root-directory> (REQUIRED) Directory from where the files will be copied, usually the
repository's root.
--output <output> (REQUIRED) Directory where the subset files will be copied,
preserving the original hierarchy.
-?, -h, --help Show help and usage information
Example with a project:
dotnet subset restore /source/complexapp/complexapp.csproj --root-directory /source/ --output /tmp/restore_subset/
Example with a solution:
dotnet subset restore /source/complexapp.sln --root-directory /source/ --output /tmp/restore_subset/
Please check these pull requests to see how to use dotnet-subset
in your Dockerfile
:
- https://github.com/othmane-kinane-nw/eShopOnContainers/pull/1/files?diff=unified&w=0
- https://github.com/othmane-kinane-nw/modular-monolith-with-ddd/pull/1/files?diff=unified&w=0
- https://github.com/othmane-kinane-nw/dotnet-docker/pull/1/files?diff=unified&w=0
- Add tests
- Automate the versionning
- Automate the deployment to NuGet
- Refactor the codebase
- Add "build" algorithm
Copyright © Nimbleways, Othmane Kinane and contributors.
dotnet-subset
is provided as-is under the MIT license. For more information see LICENSE.
- For Microsoft.Build, see https://github.com/dotnet/msbuild/blob/main/LICENSE
- For Microsoft.Build.Locator, see https://github.com/microsoft/MSBuildLocator/blob/master/LICENSE
- For System.CommandLine, see https://github.com/dotnet/command-line-api/blob/main/LICENSE.md