question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

project.assets.json is a pita

See original GitHub issue

Version used: VS2019 Preview1 and basically all versions of 2017.

After changing the TargetFramework of an SDK style Project in VS without unloading from net472 to netcoreapp2.2, i’ve noticed that the Dependencies node got a yellow triangle and doing a rebuild yielded

Resource file "[...]\obj\project.assets.json" has no target for "netcoreapp2.2".
Ensure that the restore is running and that the item "netcoreapp2.2" is included in the TargetFrameworks element for the project.

No amount of clicking rebuild, build or clean in VS helps to solve this.

So then i’ve opened the project folder and removed the obj directory (why doesn’t clean do this?), and the next rebuild yielded

Assets file '[…]\obj\project.assets.json' not found. 
Run a NuGet package restore to generate this file.

again, nothing i can do in VS fixes it. So i drop back to cmd to run dotnet restore and voila, it works.

Interestingly enough, from that moment on, changing TargetFramework back and forth worked flawlessly, with Restoring… flashing in VS statusbar.

Similiar i sometimes open Projects or have Projects that somehow become corrupted and then everything is an error of the Predefined type 'System.Object' is not defined or imported sorts. This usually requires closing VS and nuking every temporary VS artifact in the solution.

Another case where you have to manually help is (because it assumed the file that was there at some point in time would still be there)

Microsoft.NET.Sdk.targets(129,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly.
Microsoft.NET.Sdk.targets(129,5): error MSB4018: System.IO.FileNotFoundException: %USERPROFILE%\.nuget\packages\library\version\lib\net40\Library.dll
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.NET.Build.Tasks.FileUtilities.GetFileVersion(String sourcePath)
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.NET.Build.Tasks.DependencyContextBuilder.CreateRuntimeFile(String path, String fullPath)
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.NET.Build.Tasks.DependencyContextBuilder.CreateRuntimeFile(LockFileTargetLibrary library, LockFileItem item)
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.NET.Build.Tasks.DependencyContextBuilder.<>c__DisplayClass40_0.<CreateRuntimeAssemblyGroups>b__0(LockFileItem a)
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.NET.Build.Tasks.DependencyContextBuilder.CreateRuntimeAssemblyGroups(LockFileTargetLibrary targetLibrary, SingleProjectInfo referenceProjectInfo)
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.NET.Build.Tasks.DependencyContextBuilder.GetLibrary(LockFileTargetLibrary export, LockFileLookup libraryLookup, IDictionary`2 dependencyLookup, Boolean runtime)
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.NET.Build.Tasks.DependencyContextBuilder.<>c__DisplayClass36_0.<GetLibraries>b__0(LockFileTargetLibrary export)
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at System.Linq.Enumerable.<CastIterator>d__97`1.MoveNext()
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.Extensions.DependencyModel.DependencyContext..ctor(TargetInfo target, CompilationOptions compilationOptions, IEnumerable`1 compileLibraries, IEnumerable`1 runtimeLibraries, IEnumerable`1 runtimeGraph)
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.NET.Build.Tasks.DependencyContextBuilder.Build()
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.ExecuteCore()
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute()
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
Microsoft.NET.Sdk.targets(129,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

I’ve seen two encounters of this one. The first was were it was trying to use newtonsoft.json\7.0.1\lib\net45\Newtonsoft.Json.dll but only newtonsoft.json\12.0.1\lib\net45\Newtonsoft.Json.dll was actually restored. The second encounter was were i was analyzing a obfuscated nuget dependency so i had a deobfuscator run and then i got two dlls in the directory, Library.dll and Library-cleaned.dll, i’ve taken a look at the cleaned version in dnSpy and then removed it later again. Now VS complained with above error that Library-cleaned.dll was missing. I’ve killed the obj folder and rebuild worked… except that a second rebuild complained about the same error again (how many levels of cache are at play here?!), so i had to close everything and kill all temporary artifacts again to get rid of that.

To be fair, it works most of the time but when it runs into cache invalidation problems, then it needs manual Intervention to fix it.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
davkeancommented, Nov 22, 2019

The first issue called out into this thread has been fixed via https://github.com/dotnet/sdk/issues/2322. The second issue isn’t currently actionable without some sort of repro project. If you encounter again, please open a bug against http://github.com/dotnet/sdk.

1reaction
jmarolfcommented, Jun 10, 2019

There has been work here to try and improve this, but I don’t think I’ll call this “fixed” yet. I’ll investigate the remaining problems (and file separate, actionable bugs)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assets file project.assets.json not found. Run a NuGet ...
To fix this error from Tools > NuGet Package Manager > Package Manager Console simply run: dotnet restore. The error occurs because the ......
Read more >
NETSDK1004: Assets file not found - .NET CLI
NuGet writes a file named project.assets.json in the obj folder, and the .NET SDK uses it to get information about packages to pass...
Read more >
project.assets.json does not work with shared intermediates
The assets file does not: project.assets.json. This is going to lead to clashes when projects share intermediate directories, ...
Read more >
Assests file project.assets.json file not found
I tried to use VS 2017 to open all my working projects, all failed with the error message: Assests file ....\obj\project.assets.json not fould....
Read more >
1 Pita Bread Lottie Animations - Free in JSON, LOTTIE, GIF
Download 1 Pita Bread Lottie Animations for free or premium in JSON, LOTTIE, GIF, AEP or MP4 formats. Bring motion to your designs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found