C
C#3mo ago
Turwaith

Nuget restore (via gitlab runner) fails at a specific package

I am trying to set up a windows gitlab runner to build and publish my WPF .NET Framework 4.8 project. My gitlab-ci.yml file looks as follows:
stages:
- build_and_publish

build_and_publish:
stage: build_and_publish
script:
- 'nuget locals all -clear'
- 'nuget restore $env:SOLUTION_NAME -SolutionDirectory .'
- 'dotnet add "$env:PROJECT_PATH" package Microsoft.Toolkit.Uwp.Notifications --version 7.1.3'
- '& "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe" $env:SOLUTION_NAME /p:Configuration=Release /p:Platform="Any CPU" /p:OutputPath="$env:CI_PROJECT_DIR\bin\Release\"'
- 'mkdir Publish'
- 'xcopy /I /E /Y "$env:CI_PROJECT_DIR\bin\Release\*" Publish/'
- 'Compress-Archive -Path Publish\* -DestinationPath Publish\Product.zip -Force'
artifacts:
name: "Product-${CI_COMMIT_REF_NAME}"
paths:
- Publish/Product.zip
expire_in: never
tags:
- windows

variables:
SOLUTION_NAME: './Source/Product.sln'
PROJECT_PATH: './Source/Product.GUI/Product.GUI.csproj'

cache:
paths:
- .nuget/
stages:
- build_and_publish

build_and_publish:
stage: build_and_publish
script:
- 'nuget locals all -clear'
- 'nuget restore $env:SOLUTION_NAME -SolutionDirectory .'
- 'dotnet add "$env:PROJECT_PATH" package Microsoft.Toolkit.Uwp.Notifications --version 7.1.3'
- '& "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe" $env:SOLUTION_NAME /p:Configuration=Release /p:Platform="Any CPU" /p:OutputPath="$env:CI_PROJECT_DIR\bin\Release\"'
- 'mkdir Publish'
- 'xcopy /I /E /Y "$env:CI_PROJECT_DIR\bin\Release\*" Publish/'
- 'Compress-Archive -Path Publish\* -DestinationPath Publish\Product.zip -Force'
artifacts:
name: "Product-${CI_COMMIT_REF_NAME}"
paths:
- Publish/Product.zip
expire_in: never
tags:
- windows

variables:
SOLUTION_NAME: './Source/Product.sln'
PROJECT_PATH: './Source/Product.GUI/Product.GUI.csproj'

cache:
paths:
- .nuget/
Now my project contains the following external packages: - Microsoft.Toolkit.Uwp.Notifications/7.1.3 - PDFtoPrinter/1.5.0 - Serilog.Sinks.File - Serilog Now the runner can successfully restore all the package EXCEPT the first one (Notifications). I have even, as you can see, specifically added the package through the script. It definitely is available on the nuget source. On my local machine (Windows 11, Rider) there is not a single problem with restore and build. Does anyone have any idea why my windows runner fails at restoring this specific package?
4 Replies
Turwaith
Turwaith3mo ago
It does not matter whether I specifically add the packge in the script or not. Both cases generate the same error
reflectronic
reflectronic3mo ago
using nuget.exe is not really recommended anymore is your project an SDK-style project? like, do you have <Project Sdk="Microsoft.NET.Sdk"> as the first line, or is it the uglier format
Turwaith
Turwaith3mo ago
No, it is the old, ugly version. Also I got some more insight. It is specifically the package Microsoft.Toolkit.Uwp.Notifications/7.1.3 that is failing. The verbose log of the runner says that it could not be found at the location where the nuget packages are downloaded to. The thing is... it is there. I checked the location on the server and the package is there. Is has the same permissions etc as all the other packages which work. Also, when going to the solution location where the runner downloads the git repo to, open a powershell prompt there and go "nuget restore", it works perfectly fine. It finds all the packages and restores them.
reflectronic
reflectronic3mo ago
ok. so, in general, i would suggest changing to the new format if you could, it works even with WPF on .NET 4.8, and it will bring benefits (like, better performance and more modern features in visual studio, ability to use dotnet commands, etc.) if you cannot... do you have a packages.config file in your repo, or are you using PackageReference