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

Viewed 2576

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>
1 Answers

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

Related