Error I received
- The project has not been restored or restore failed – run
dotnet restore
-
The project does not list one of ‘win10-x64, win81-x64, win8-x64, win7-x64’ in the ‘runtimes’ section.
-
You may be trying to publish a library, which is not supported. Use
dotnet pack
to distribute libraries.
Can not find runtime target for framework ‘.NETCoreApp,Version=v1.1’ compatible with one of the target runtimes: ‘win10-x64, win81-x64, win8-x64, win7-x64’.
How to fix it
Open your project.json and under “dependencies” change
"Microsoft.NETCore.App": "1.1.0",
to
"Microsoft.NETCore.App": { "version": "1.1.0", "type": "platform" },
Then re-run your app.
How it happened
I’m still using Visual Studio 2015, but I have .NET Core 1.1 downloaded and installed and I wanted to upgrade to .NET Core 1.1 and update to all the latest ASP.NET Core 1.1 packages.
I went to File => New Project => ASP.NET Core Web Application, which proceeded to give me .NET Core 1.0.1, which was expected. I followed the upgrade path, but I forgot to hit “Save” on my project.json in step 2, when I changed the values to .NET Core 1.1.0. Therefore, it did not restore the .NET Core 1.1 NuGet package.
So when I went to the NuGet UI under Updates, .NET Core was an option to update, which I didn’t realize when I hit “Update All.” Well that jacked with my project.json in this way…
Before:
After:
NuGet removed my JSON nested object with just the version number. What the “type”:”platform” does is it tells my project that it expects .NET Core will already be installed on the machine, therefore it will not bundle .NET Core with my app.
When “type” : “platform” is NOT specified, then it assumes I am bundling .NET Core WITH my app. In that case, I need to specify the exact platforms that I’m targeting (i.e. Windows 10, Linux, Mac, etc.) in the “runtimes” section. However, that “runtimes” section was not there previously, because I was targeting the platform.
This seems like it would be a bug with NuGet. It should only update the Version, and not overwrite anything else. Maybe this gets fixed during the switch to csproj coming soon. I’m not going to file a bug at this point on GitHub, because I doubt they make the investment to fix this in project.json.