I'm attempting to set up an Azure DevOps build pipeline against a .NET Framework 4.7.2 solution which contains a Visual Studio Installer Project. I've set up a self-hosted agent on a Windows Server 2019 VM, which has Visual Studio 2019 Community installed. The build pipeline contains the NuGet Installer task, followed by the NuGet task, set up to restore the referenced NuGet Packages. Below is the YAML snippet:
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '$(solution)'
Running a build with this configuration however, results in the following error in the build logs:
[error]The nuget command failed with exit code(1) and error(C:\##############.vdproj(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.)
This appears to be due to a performance enhancement that's been made in newer versions of nuget.exe. The suggestion, based on this GitHub issue, is to enable skipping non-existent package targets using the RestoreUseSkipNonexistentTargets
MSBuild setting.
The GitHub issue mentions using the NUGET_RESTORE_MSBUILD_ARGS
NuGet CLI environment variable in order to set this property, but I don't know how this can be achieved through the NuGet build task.
Since NuGet is now integrated with MSBuild, I then attempted to set this property to false
through a command-line argument on the NuGet task. I modified the YAML, setting the command to custom
in order to pass arguments. I based the syntax off of the MSBuild restore documentation. It now looks like follows:
- task: NuGetCommand@2
inputs:
command: 'custom'
arguments: 'restore "$(solution)" -p:RestoreUseSkipNonexistentTargets=false'
This build configuration results in the following error:
[error]The nuget command failed with exit code(1) and error(Unknown option: '-p:RestoreUseSkipNonexistentTargets=false')
My question is, how do I go about getting the NuGet restore task to skip package restore on .vdproj projects?
EDIT
The other project in the solution is a C# WinForms .NET Framework project. We're using packages.config rather than PackageReference.
nuget restore proj1\packages.config -PackagesDirectory ..\packages
. See here. – Chickabiddymsbuild /t:restore
, this one anddotnet restore
can be suitable for your current situation. Also, they're suitable for that when you have dozens of projects in solution, butmsbuild /t:restore
and dotnet works for .net fx projects that use PackageReference instead of packages.config. So i ask in first comment whether you use packages.config or packagereference. – Chickabiddymsbuild /t:restore
only works for PackageReference. I appreciate all the provided solutions & options. I will work on this some more with the above info. – Deodorize