project.assets.json is a pita
See original GitHub issueVersion 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:
- Created 5 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
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.
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)