Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"unknown keyword platform" when restoring in Visual Studio

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?

like image 907
Nate Barbettini Avatar asked May 21 '16 01:05

Nate Barbettini


1 Answers

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.

like image 110
Nate Barbettini Avatar answered Oct 22 '22 16:10

Nate Barbettini