Nick
Nick

Reputation: 1934

Visual Studio dotnet command line tools wrong version

I'm having an issue where the dotnet command line tools are the wrong version. I just uninstalled and reinstalled the latest .NET Core Tools from https://www.microsoft.com/net/core#windows

Then I opened up VS2015 (Update 3), and clicked on Help -> About Microsoft Visual Studio. There I can see the correct version of .NET Core tools:

Microsoft .NET Core Tools (Preview 2) 14.1.20624.0

However, when I go to Tools -> NuGet Package Manager -> Package Manager Console and type in

dotnet --version

I get this:

1.0.0-preview1-002702

This is wrong. This should be 1.0.0-preview2-00300* (something).

This is a major issue because none of my nuget package restores work now. I get a ton of "Package Microsoft.Aspnetcore.Mvc1.0.0 does not support framework .NETCoreApp, Version=v1.0" type of errors, as seen here: Package Microsoft.Aspnetcore.Mvc1.0.0 does not support framework .NETCoreApp, Version=v1.0

What is going on? How can I make the Package Manager Console recognize that the .NET Core tools is version Preview 2, not Preview 1?

Upvotes: 4

Views: 6320

Answers (4)

John777
John777

Reputation: 126

For some reason dotnet chooses the previous version, but by default should choose the highest. There is a workaround to force it.

Please, try the following :

  1. Go to : C:\Program Files\dotnet\sdk
  2. Remove the SDK that dotnet insists on using
  3. Run the console and write : dotnet --version. You should have following error :

Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
You intended to execute a .NET program:
The application '--version' does not exist. You intended to execute a .NET SDK command:
A compatible installed .NET SDK for global.json version [2.2.101] from [C:\global.json] was not found.
Install the [2.2.101] .NET SDK or update [C:\global.json] with an installed .NET SDK:
1.1.14 [C:\Program Files\dotnet\sdk]
(...)
5.0.401 [C:\Program Files\dotnet\sdk]
5.0.402 [C:\Program Files\dotnet\sdk]

  1. Open file : C:\global.json
  2. Override version field with intended version, for example to net5 with "5.0.402" :
 {
      "sdk": {
        "version": "5.0.402"
      }
    }

Ref : https://learn.microsoft.com/en-us/dotnet/core/tools/global-json?tabs=netcore3x

Upvotes: 0

SliverNinja - MSFT
SliverNinja - MSFT

Reputation: 31651

Upgraded to latest .NET Core SDK 1.0.3, but dotnet.exe was still looking for project.json. It seems that you need to remove any preview versions of dotnet SDK as they have precedence over version number.

After uninstalling ALL SDK Previews (1.0.0-preview2-) from Add/Remove Programs, dotnet.exe found the latest 1.0.3 installed SDK.

Uninstall .NET Core Previews

enter image description here

The key was to run dotnet --info and verify Product Information => Version attribute. If it says preview, it's not using the latest .NET Core SDK version and you will get errors like so when running dotnet build or dotnet run:

Couldn't find 'project.json' in current directory

Upvotes: 1

Jim W
Jim W

Reputation: 5026

I've just resolved versioning issues moving from 1.0.0 to 1.1.0

Your project.json needs to change to the new template, eg.

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        },
        "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
        "Microsoft.AspNetCore.Mvc": "1.0.1",
        "Microsoft.AspNetCore.Routing": "1.0.1",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
        "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
        "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
        "Microsoft.Extensions.Configuration.Json": "1.0.0",
        "Microsoft.Extensions.Logging": "1.0.0",
        "Microsoft.Extensions.Logging.Console": "1.0.0",
        "Microsoft.Extensions.Logging.Debug": "1.0.0",
        "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
      },
      "imports": "dnxcore50"
    }
  }
}

I got this from https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-net-core-1-1/

As long as the core 1.1 SDK is installed, when running the "dotnet.exe" command it should pick up the correct SDK to use. For interest, the "dotnet.exe" command seems to be 'global' in that it applies to multiple versions. There isn't one dotnet.exe for each version. The SDK install layout shows this, dotnet.exe lives at

C:\Program Files\dotnet

and the SDKs themselves are at

C:\Program Files\dotnet\sdk\1.0.0-preview2-1-003177 C:\Program Files\dotnet\sdk\1.0.0-preview2-003131

After changing the project.json you need to do

dotnet restore

and then you can do

dotnet build
dotnet run

Upvotes: 1

Ralf Bönning
Ralf Bönning

Reputation: 15465

Because the side by side manner of .net Core installation, multiple versions can coexist on one machine. Therefore the version the dotnet.exe (.NET Core Command Line Interface) resolves can be different to the version of the latest installed version.

From https://learn.microsoft.com/de-de/dotnet/articles/core/tools/index#driver

First, the driver will determine the version of the tooling that you want. You can specify the version in the global.json file using the sdkVersion property. If that is not available, the driver will find the latest version of the tools that is installed on disk and will use that version. Once the version is determined, it will execute the command.

Please check, if a global.json in your project folder exists that may define the sdkVersion explicitly to 1.0.0-preview1-002702 and change it to 1.0.0-preview2-003121.

Upvotes: 4

Related Questions