0

I have a .Net 6 project, I am getting the below error.

Error: NuGet packages need to be restored before building. NuGet MSBuild targets are missing and are needed for building. The NuGet MSBuild targets are generated when the NuGet packages are restored.

csproj file:

<PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <OutputType>Exe</OutputType>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <DockerfileContext>..\..</DockerfileContext>
    <Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

Visual studio version: 17.4.2

I have followed this question also (restoring the packages), But it didn't help.

But I am able to build from the terminal using dotnet build successfully.

Also, I have other projects targeting .net 6 and I can build successfully using visual studio.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
  • Can this be some strange connectivity issues with VS2022? Had also some issues with the 2022 version and had to use the 2019 version instead. Can you try to restore the packages via CLI? And also try to clean the obj and bin folder if they are present – Aaron Feb 09 '23 at 07:40
  • I have tried cleaning the solution, but it didn't work. @Aaron – Vivek Nuna Feb 09 '23 at 07:45
  • Does the restore work in VS Mac? That error happens when VS Mac cannot find the project's obj/project.assets.json file. Does this project use some custom NuGet restore or put this file somewhere else? – Matt Ward Feb 09 '23 at 09:49
  • @MattWard restore is happening correctly – Vivek Nuna Feb 09 '23 at 11:13
  • Does the obj/project.assets.json file exists for the project that is failing even though restore is succeeding? – Matt Ward Feb 10 '23 at 10:23
  • @MattWard it’s present – Vivek Nuna Feb 10 '23 at 12:15

0 Answers0