Challenge:
Since dotnet/sdk:8.0, dotnet restore takes too long on GitLab CI with Docker.
Solution:
NuGet team has proposed a workaround for this issue:
https://github.com/NuGet/Home/issues/13062
Workaround Steps:
- Create a file named NuGet.config in the root folder of your project.
- Add the following content to the file:
<?xml version="1.0" encoding="utf-8"?> <configuration> <config> <add key="globalPackagesFolder" value="NuGetPackages" /> </config> </configuration>
- Commit the changes to your source control.
- Update your GitLab CI config to use the new NuGet.config file.
image: mcr.microsoft.com/dotnet/sdk:8.0 stages: - restore - build restore: stage: restore script: - dotnet restore --configfile NuGet.config build: stage: build script: - dotnet build
Additional Information:
- This workaround is not a permanent fix, and it may not work for all projects.
- The NuGet team is working on a permanent fix for this issue.
- In the meantime, you can use this workaround to reduce the time it takes for dotnet restore on GitLab CI with Docker.