question

WPSmokeball-1244 avatar image
1 Vote"
WPSmokeball-1244 asked DavidBroadfoot-3823 published

NuGet restore of a multi-targeted project yields error MSB4018 "WriteRestoreGraphTask"

We are going through the process of multi-targeting our projects, for the most part it works, things compile.

But for one project we've run into the following stack trace when running nuget restore on the project

 MSBuild auto-detection: using msbuild version '17.0.0.45303' from 'C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\bin'.
 C:\Users\wpang\AppData\Local\Temp\NuGetScratch\4wcxk1dx.nnr.nugetrestore.targets(160,5): error MSB4018: The "WriteRestoreGraphTask" task failed unexpectedly. [C:\Users\wpang\AppData\Local\Temp\NuGetScratch\npu0my22.xrd.nugetinputs.targets]
 C:\Users\wpang\AppData\Local\Temp\NuGetScratch\4wcxk1dx.nnr.nugetrestore.targets(160,5): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object. [C:\Users\wpang\AppData\Local\Temp\NuGetScratch\npu0my22.xrd.nugetinputs.targets]
 C:\Users\wpang\AppData\Local\Temp\NuGetScratch\4wcxk1dx.nnr.nugetrestore.targets(160,5): error MSB4018:    at NuGet.Frameworks.AssetTargetFallbackFramework..ctor(NuGet.Frameworks1190085.NuGetFramework framework, IReadOnlyList`1 fallbackFrameworks) [C:\Users\wpang\AppData\Local\Temp\NuGetScratch\npu0my22.xrd.nugetinputs.targets]
 C:\Users\wpang\AppData\Local\Temp\NuGetScratch\4wcxk1dx.nnr.nugetrestore.targets(160,5): error MSB4018:    at NuGet.Commands.AssetTargetFallbackUtility.GetFallbackFramework(NuGet.Frameworks1190085.NuGetFramework projectFramework, IEnumerable`1 packageTargetFallback, IEnumerable`1 assetTargetFallback) [C:\Users\wpang\AppData\Local\Temp\NuGetScratch\npu0my22.xrd.nugetinputs.targets]
 C:\Users\wpang\AppData\Local\Temp\NuGetScratch\4wcxk1dx.nnr.nugetrestore.targets(160,5): error MSB4018:    at NuGet.Commands.AssetTargetFallbackUtility.ApplyFramework(TargetFrameworkInformation targetFrameworkInfo, IEnumerable`1 packageTargetFallback, IEnumerable`1 assetTargetFallback) [C:\Users\wpang\AppData\Local\Temp\NuGetScratch\npu0my22.xrd.nugetinputs.targets]
 C:\Users\wpang\AppData\Local\Temp\NuGetScratch\4wcxk1dx.nnr.nugetrestore.targets(160,5): error MSB4018:    at NuGet.Commands.MSBuildRestoreUtility.AddPackageTargetFallbacks(PackageSpec spec, IEnumerable`1 items) [C:\Users\wpang\AppData\Local\Temp\NuGetScratch\npu0my22.xrd.nugetinputs.targets]
 C:\Users\wpang\AppData\Local\Temp\NuGetScratch\4wcxk1dx.nnr.nugetrestore.targets(160,5): error MSB4018:    at NuGet.Commands.MSBuildRestoreUtility.GetPackageSpec(IEnumerable`1 items) [C:\Users\wpang\AppData\Local\Temp\NuGetScratch\npu0my22.xrd.nugetinputs.targets]
 C:\Users\wpang\AppData\Local\Temp\NuGetScratch\4wcxk1dx.nnr.nugetrestore.targets(160,5): error MSB4018:    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() [C:\Users\wpang\AppData\Local\Temp\NuGetScratch\npu0my22.xrd.nugetinputs.targets]
 C:\Users\wpang\AppData\Local\Temp\NuGetScratch\4wcxk1dx.nnr.nugetrestore.targets(160,5): error MSB4018:    at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext() [C:\Users\wpang\AppData\Local\Temp\NuGetScratch\npu0my22.xrd.nugetinputs.targets]
 C:\Users\wpang\AppData\Local\Temp\NuGetScratch\4wcxk1dx.nnr.nugetrestore.targets(160,5): error MSB4018:    at NuGet.Commands.MSBuildRestoreUtility.GetDependencySpec(IEnumerable`1 items) [C:\Users\wpang\AppData\Local\Temp\NuGetScratch\npu0my22.xrd.nugetinputs.targets]
 C:\Users\wpang\AppData\Local\Temp\NuGetScratch\4wcxk1dx.nnr.nugetrestore.targets(160,5): error MSB4018:    at NuGet.Build.Tasks.WriteRestoreGraphTask.Execute() [C:\Users\wpang\AppData\Local\Temp\NuGetScratch\npu0my22.xrd.nugetinputs.targets]
 C:\Users\wpang\AppData\Local\Temp\NuGetScratch\4wcxk1dx.nnr.nugetrestore.targets(160,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Users\wpang\AppData\Local\Temp\NuGetScratch\npu0my22.xrd.nugetinputs.targets]
 C:\Users\wpang\AppData\Local\Temp\NuGetScratch\4wcxk1dx.nnr.nugetrestore.targets(160,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\Users\wpang\AppData\Local\Temp\NuGetScratch\npu0my22.xrd.nugetinputs.targets]


The project is upgraded to the new .NET SDK project style and then the TargetFrameworks are hand edited to include the following

<TargetFrameworks>net40;net5.0-windows</TargetFrameworks>

Not exactly sure why this error is occurring.

Does anyone have any ideas or pointers I can look at to try.





vs-msbuilddotnet-package-management
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, @WPSmokeball-1244
I tried but couldn't reproduce your issue on my side.
You can try to clear the cache of nuget, and then perform the Restore operation.
I did some searching and found this thread similar to your issue.


0 Votes 0 ·

1 Answer

DavidBroadfoot-3823 avatar image
1 Vote"
DavidBroadfoot-3823 answered DavidBroadfoot-3823 published

This error was on nuget 5.X. Upgrading to nuget 6.X seems to fix the issue

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.