'NuGet.targets(565,5): error : Value cannot be null. (Parameter 'path1') - _GenerateRestoreGraph -- FAILED

I am able to build the application and run it properly on my local machine. Build was working before upgrading nuget packages to newer versions.

I've made sure that the proper SDK's were installed. Locally running the latest version of visual studio. Specifically Visual Studio 2019.

I did use google quite a bit but had no luck in ideas of troubleshooting.

Push to build server (TeamCity Hosted on Windows with a build agent on windows.) and I get the following

Build Error detailed

>Done executing task "MSBuild" -- FAILED.
>Done building target "_GenerateRestoreGraph" in project "LBX - Data Worker.csproj" -- FAILED.
>Done Building Project "C:\TeamCity\BuildAgent\work\9316ac4346c6016c\LBX Capital Collector\LBX - Data Worker.csproj" (Restore target(s)) -- FAILED.

.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RootNamespace>LBX_DataWorker</RootNamespace>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <GenerateProgramFile>False</GenerateProgramFile>
    <OutputPath>bin\Release</OutputPath>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <GenerateProgramFile>False</GenerateProgramFile>
    <OutputPath>\bin\Debug</OutputPath>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.10" />
    <PackageReference Include="Microsoft.AspNetCore.SignalR.Common" Version="5.0.10" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.10">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.10" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.10">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="5.0.1" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
    <PackageReference Include="NUnit" Version="3.13.2" />
    <PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
    <PackageReference Include="ServiceStack.Text" Version="5.12.0" />
    <PackageReference Include="System.ServiceProcess.ServiceController" Version="5.0.0" />
    <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
  </ItemGroup>

  <ItemGroup>
    <None Update="appsettingsProd.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="appsettingsDev.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="FredSeries.csv">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="GeneralLedgerMissingContractIDs.csv">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Database\LBX_Capital\Migrations\" />
  </ItemGroup>

</Project>


Solution 1:[1]

Ran windows updates on Server 2019 (has Worker Agent). Restarted the server. Darn thing started building.

Solution 2:[2]

I had this problem on our build server (Jenkins) after Windows patching and a restart. I found that the build script worked when logged on locally under the same account that Jenkins runs on, but not from Jenkins. I eventually figured out that the some variables were missing/different in the Jenkins session. I resolved it by adding this to my build script:

SET APPDATA=C:\Users\<Jenkins User Account>\AppData\Roaming
SET LOCALAPPDATA=C:\Users\<Jenkins User Account>\AppData\Local
SET TEMP=C:\Users\<Jenkins User Account>\AppData\Local\Temp
SET TMP=C:\Users\<Jenkins User Account>\AppData\Local\Temp
SET USERPROFILE=C:\Users\<Jenkins User Account>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HellKnight Hicks
Solution 2