I can't seem to find the correct settings for my DevOps build pipeline to enable it to restore NuGet packages so that the build process will locate them.
The first issue which I have over come is that the default settings pointed the restore at my .sln file which caused it to print out:
Nothing to do. None of the projects in this solution specify any packages for NuGet to restore.
It's a Visual Studio 2017 website .sln file and doesn't contain information about NuGet and there is no .csproj which other answers have suggested.
I got round the issue by pointing it at the packages.config file. Now the restore process does locate the packages which are needed, but it doesn't seem to be putting them where the "Visual Studio Build" build process can find them.
Error CS0246: The type or namespace name 'Nest' could not be found (are you missing a using directive or an assembly reference?)
I have looked in the build process section, but I couldn't find anything useful as the only reference is marked with:
This option is deprecated. To restore NuGet packages, add a NuGet Tool Installer
Which is what I'm already attempting to do. I have tried moving the destination directory of the NuGet restore to bin
and other places, but it didn't make a difference.
Is there a step which I'm missing to move the files after they have been restored? Or a parameter I need to pass when it's building to tell it where the package files are?
Azure DevOps, Restore NuGet packages for “Visual Studio Build” when using a website.sln?
You should use the NuGet Installer task during your build pipeline.
The option Restore NuGet Packages is deprecated:
This option is deprecated. To restore NuGet packages, add a NuGet Installer step before the build
So to resolve this issue, please try to use NuGet Installer task, go to Package tab, and add the NuGet restore task.
You can specify the packages.config or the .sln file to restore packages. When you specify the packages.config, you also need provide the Destination directory, and the default value is /packages:
After taking a look at this for a different pipeline I worked out the answer. In short it was to was to do with the packages.config and sln file locations along with the relative paths used to restore and search for the packages.
The long answer.
In the Build solution log after it gives the error for the missing files it lists all the places it's checking.
For SearchPath "{CandidateAssemblyFiles}".
For SearchPath "{HintPathFromItem}".
For SearchPath "{TargetFrameworkDirectory}".
For SearchPath "bin\Release\".
For SearchPath "{RawFileName}".
The HintPathFromItem was most interesting as it mentions the package folder.
For SearchPath "{HintPathFromItem}".
Considered "packages\log4net.2.0.0\lib\net40-full\log4net.dll", but it didn't exist.
With this in mind I checked where the NuGet restore was placing the packages folder and found that it was adding it at the same level as the website root. In my case by changing the destination directory to
packages
instead of
/packages
or
../packages
moved it up one level to inside the root of the website to where the build was searching.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With