project.json doesn't have a runtimes section, add '“runtimes”: { “win”: { } }' to project.json within a .Net Class Library

Recently I've started experiencing weird build errors when switch branches on a product.
Error : Your project.json doesn't have a runtimes section. You should add '"runtimes": { "win": { } }' to your project.json and then re-run NuGet restore.
It's a weird sounding error and the fact it mentions project.json makes it sound like a hangup from when .Net Core and Standard were using project.json files before they became .csproj files again.

My first thought to resolve this is always try a clean and build, particularity when swapping branches things could get left hanging around but this doesn't work.

I took a closer look at the projects affected and the cause is to do with one of the branches of our product. It's an early development branch of a new feature where the project has become .Net Standard 2.0 but also targets .Net 4.5, where as the support and main dev branch are still the full framework class libraries.  The cause is most certainly to do with how msbuild produces different artifacts upon each branch.

The solution: simply delete the obj folder from the affected projects when you switch branches, there are no left over artifacts then affecting the build.

For those that are interested or if you don't want to be deleting your obj folder all the time the error actually only happens if there is a project.assets.json within the obj folder as even the new .csproj generates this file. Delete it when you switch branches and your builds will work again.

[Update 16/03/2018]
This error can also seen as
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(186,5): error : Your project is not referencing the ".NETPortable,Version=v4.5,Profile=Profile7" framework. Add a reference to ".NETPortable,Version=v4.5,Profile=Profile7" in the "frameworks" section of your project.json, and then re-run NuGet restore.

Again its the same issue, delete the project.assets.json and everything will build fine.

[Update 21/03/2018]
Another update! Since Visual Studio's 15.6.3 update this also happens if you have Resharper installed. This times it errors:

Assets file 'project\obj\project.assets.json' doesn't have a target for '.NETFramework,Version=v4. .....
Unfortunately at present the only way to solve this is to uninstall Resharper, suspending it isn't enough :(

This is being tracked at: https://developercommunity.visualstudio.com/content/problem/218852/build-failed-after-upgrade-to-1563-doesnt-have-a-t.html

[Update 22/03/2018]
This has been tracked in https://developercommunity.visualstudio.com/content/problem/218674/assets-file-cxxxxxxobjprojectassetsjson-doesnt-hav.html and is now released as part of the 15.6.4 update.

Comments

Popular posts from this blog

GZip Compression of JSON and IIS

An unexpected exception which resulted in a gentle reminder of how Linq works...

WebUSB - An unexpected update...