I recently got the error code "NETSDK1005" when i tried to run (dotnet run) my application:
C:\Program Files\dotnet\sdk\5.0.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1005: Assets file 'C:\Test\code\App\obj\project.assets.json' doesn't have a target for 'net5.0'. Ensure that restore has run and that you have included 'net5.0' in the TargetFrameworks for your project. [C:\Test\code\App\NetCore.Docker.Peter.csproj]
My project would not build either:
C:\Program Files\dotnet\sdk\5.0.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1005: Assets file 'C:\Test\code\App\obj\project.assets.json' doesn't have a target for 'net5.0'. Ensure that restore has run and that you have included 'net5.0' in the TargetFrameworks for your project. [C:\Test\code\App\NetCore.Docker.Peter.csproj]
After googling I found a similar issue with older versions of nuget. I think the issue was that I built and restored my solution in Visual Studio and then went on to use the command line. I fixed this by running the following command to restore all packages:
dotnet restore --force
Without --force it will believe everything is up to date, so remember to force it. After this my dotnet build and dotnet run were successful.
An alternative
As Baomei Fan mentioned in the comments down below, perhaps this could be an issue with the version of nuget, Baomei updated to NuGet version to 5.8.x which solved the issue as well!
That is it
I hope you find this helpful! Please leave a comment below if you did.