"unknown keyword platform" when restoring in Visual Studio
Asked Answered
B

3

6

I'm converting a project from .NET Core RC1 to RC2. I've installed the Visual Studio tooling preview package and updated the VS Nuget plugin to the latest version.

This is a test project, so I need to add Microsoft.NETCore.App to my project.json per the library guide. It looks like this:

{
  "dependencies": {
    "dotnet-test-xunit": "1.0.0-rc2-build10015",
    "FluentAssertions": "4.2.1",
    "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-final",
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-3002702"
    },
    "xunit": "2.1.0"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": [ "dotnet", "portable-net45+win8" ]
    }
  },
  "testRunner": "xunit",
}

The project restores and builds on the command line (dotnet restore/build). However, when Visual Studio tries to restore packages, I get this error:

PATH=.\node_modules\.bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External;%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\git
C:\Users\Nate\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc2-20221\bin\dnx.exe "C:\Users\Nate\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc2-20221\bin\lib\Microsoft.Dnx.Tooling\Microsoft.Dnx.Tooling.dll" restore "C:\Users\Nate\Documents\stormpath-dotnet-config\test\Stormpath.Configuration.Test"
Microsoft .NET Development Utility Clr-x86-1.0.0-rc2-20221
  CACHE https://api.nuget.org/v3/index.json
Restoring packages for C:\Users\Nate\Documents\stormpath-dotnet-config\test\Stormpath.Configuration.Test\project.json
----------
C:\Users\Nate\Documents\stormpath-dotnet-config\test\Stormpath.Configuration.Test\project.json(0,0): Error: Microsoft.Dnx.Runtime.FileFormatException: unknown keyword platform ---> System.InvalidOperationException: unknown keyword platform
   at Microsoft.Dnx.Runtime.LibraryDependencyType.Parse(String keyword)
   at Microsoft.Dnx.Runtime.ProjectReader.PopulateDependencies(String projectPath, IList`1 results, JsonObject settings, String propertyName, Boolean isGacOrFrameworkReference)
   at Microsoft.Dnx.Runtime.ProjectReader.ReadProject(Stream stream, String projectName, String projectPath, ICollection`1 diagnostics)
   at Microsoft.Dnx.Runtime.Project.TryGetProject(String path, Project& project, ICollection`1 diagnostics)
   --- End of inner exception stack trace ---
   at Microsoft.Dnx.Runtime.Project.TryGetProject(String path, Project& project, ICollection`1 diagnostics)
   at Microsoft.Dnx.Tooling.RestoreCommand.<RestoreForProject>d__69.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Dnx.Tooling.RestoreCommand.<>c__DisplayClass68_0.<<Execute>b__2>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Dnx.Tooling.RestoreCommand.<Execute>d__68.MoveNext()
----------
Restore failed
unknown keyword platform
NuGet Config files used:
    C:\ProgramData\NuGet\Config\Microsoft.VisualStudio.Offline.config
    C:\Users\Nate\AppData\Roaming\NuGet\nuget.config
Feeds used:
    https://api.nuget.org/v3-flatcontainer/
    C:\Users\Nate\Documents\LocalNuget
    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

Obviously the "type": "platform" property is throwing it off, but shouldn't this work with the latest tooling release?

Bernardinebernardo answered 21/5, 2016 at 1:37 Comment(0)
B
15

Tl;dr - Update or replace global.json with the version value below.

Also, make sure that NuGet is updated. (Thanks for the tip, gigi!)

This error is caused by an old tooling version in global.json. If the value hasn't been updated (easy to miss when migrating projects), this error will inexplicably be thrown even with the newest tooling installed.

Your global.json might look like this for an RC1-era project:

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-rc1-update1"
  }
}

For .NET Core 1.0 RTM, it should look like:

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview2-003121"
  }
}

The tricky part is that even version: 1.0.0-rc2-20221 will not work! version: 1.0.0-preview2-003121 is the correct value as of now. The global.json file above will restore and compile with both Visual Studio and dotnet build/dotnet run.

Bernardinebernardo answered 21/5, 2016 at 1:37 Comment(12)
Damien Edwards used "version": "1.0.0-rc2-002392"... is that out of date github.com/aspnet/live.asp.net/commit/…? Where is this documented?Recalcitrate
I'm going to just delete the global.json file and see how that goes.Recalcitrate
@Aligned: I'm not sure if that works or not. Can you restore in VS with the value Damien used?Bernardinebernardo
VS recreated the global.json with what you had after I deleted it.Recalcitrate
I have version 1.0.0-preview1-002702 and I get Error: unknown keyword platform when I run dnx . web.Marlea
@orad: If you have RC2 installed, you should be using dotnet run, not dnx.Bernardinebernardo
@nate-barbettini worked! thanks. Is dnx residual of older versions? Can I uninstall it?Marlea
@orad: Yes, dnx is deprecated. You should be able to uninstall it. Btw, if this question/answer was helpful, mind upvoting? :)Bernardinebernardo
@nateBarbettini for me this doesn't work. tried to set the sdk version in the global.json but still getting the same error. any other idea would be welcomeHildegard
@Hildegard Try scaffolding a new project with dotnet new and see if that restores and compiles.Bernardinebernardo
I have all the latest versions (I started with rc2 tooling) and I'm getting this error on our build server and locally when nuget restore is called (I have some older projects) and the new project system. Please send me a message on slack..Symbolist
I solved using nuget.exe 3.5 beta. Now it works perfectly. ThanksHildegard
S
0

Adding Below Code Will Definitely solve your problem . I have gone through this error and reached this question but Answer above does fit to my scenario so i am adding an another answer that helped me -

See In my case we need to add EntityFrameworkCore.Tools and EntityFrameworkCore.Designin project.json Code that was needed to be added in project .json

{
    "dependencies": {
        "Microsoft.EntityFrameworkCore.Design": {
            "version": "1.0.0-*",
            "type": "build"
        }
    },
    "tools": {
        "Microsoft.EntityFrameworkCore.Tools": "1.0.0-*"
    }
}

Below is the second change that may help you

"frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dnx451",
        "portable-net45+win8"
      ]
    }
  },
Schizo answered 6/7, 2016 at 12:55 Comment(0)
A
0

After trying above steps, the issue is not resolved . Then I found out to install .NET Core - .NET Core runtime and framework (https://github.com/dotnet/cli) manually .

After installing, issue got resolved and make sure to map the node.js path in tools->option->projects and solutions->External web tools

enter image description here

Absorbing answered 7/1, 2017 at 12:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.