project.assets.json doesn't have a target for 'net472'. Ensure that restore has run and that you have included 'net472' VS2019

5.2k Views Asked by At

I get this error when i try to build the app. I think somehow i need to do a .net restore but i dont know if it will work.. And i want to make it via code. The .csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <Sdk Name="Microsoft.Build.CentralPackageVersions" Version="2.0.36" />
  <Import Project="..\..\..\..\MSBuild\root_configuration.props" />
  <PropertyGroup>
    <TargetFrameworks>net472</TargetFrameworks>
    <OutputPath>$(NUnitTestBinDir)\NunitTSAdapter</OutputPath>
    <SignAssembly>false</SignAssembly>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NUnit" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" />
    <PackageReference Include="NUnit3TestAdapter" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\NUnitTestAdapter\NUnitTestAdapter.csproj" />
    <ProjectReference Include="..\NunitTSFeature\NunitTSFeature.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="WindowsBase" />
  </ItemGroup>
</Project>
3

There are 3 best solutions below

4
Mr Qian On

Just delete the obj folder from your project folder and then build again, you will not face the issue.

Update 1

Right-click on the Project on the Solution Explorer-->Properties-->Build Event

write these on the pre-build event command line:

del  obj\project.assets.json
dotnet restore

enter image description here

0
Sky scream On

I deleted both bin and obj folder within src/common, src/domain, and src/ folders and then opened command prompt and changed to solution directory and run below command

dotnet restore
0
Hewit HN On

i spent one day for this error. I tried a lot of ways but still not successfull, such as:

  • reopen Visual studio
  • delete /obj, /bin
  • run dotnet clean/restore, reinstall workload...

Finally, i increased "Minimum Target Android Framework" in "Android targets" .csproj file, then it built OK. Maybe there is something wrong with .csproj file.