Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup SDK version into .NET Core project when global.json is not enough?

Tags:

.net-core

I found, from several sources, that the official way to setup SDK version into our .NET Core project is to add a global.json file into the project main folder.

By the way, let me remind some useful cli commands to run into your project folder:

dotnet --list-sdks list all installed SDKs

dotnet new globaljson --sdk-version 2.2.105 create the appropriate global.json file

Now my issue:

global.json is not applied, displayed versions does not match with my global.json

My csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <LangVersion>7.3</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\EmargementsListeners.Application\EmargementsListeners.Application.csproj" />
    <ProjectReference Include="..\..\EmargementsListeners.EmargProviders\Emp.Source.FakeRandomisedXbus\Emp.Source.FakeRandomisedXbus.csproj" />
    <ProjectReference Include="..\..\EmargementsListeners.Persistence\EmargementsListeners.Persistence.csproj" />
  </ItemGroup>

  <ItemGroup>
    <None Update="appsettings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>

My global.json:

{
  "sdk": {
    "version": "2.2.105"
  }
}

The result:

Sdk version doesn't match with global.json

As you see, the sdk version does not match with global.json. It should be NetCore.App 2.2.3, not 2.2.0

enter image description here

Placing this global.json into the solution folder gives the same results.

dotnet --info from my project:

dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.2.105
 Commit:    7cecb35b92

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.16299
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.105\

Host (useful for support):
  Version: 2.2.3
  Commit:  6b8ad509b6

.NET Core SDKs installed:
  1.0.4 [C:\Program Files\dotnet\sdk]
  1.1.0 [C:\Program Files\dotnet\sdk]
  2.0.0 [C:\Program Files\dotnet\sdk]
  2.0.2 [C:\Program Files\dotnet\sdk]
  2.1.4 [C:\Program Files\dotnet\sdk]
  2.1.201 [C:\Program Files\dotnet\sdk]
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.302 [C:\Program Files\dotnet\sdk]
  2.1.402 [C:\Program Files\dotnet\sdk]
  2.1.500 [C:\Program Files\dotnet\sdk]
  2.1.504 [C:\Program Files\dotnet\sdk]
  2.2.103 [C:\Program Files\dotnet\sdk]
  2.2.105 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

Question: Which step is missing to set up the SDK version to use?

like image 576
Giova Avatar asked Mar 27 '19 10:03

Giova


People also ask

Is global json required?

In general, you want to use the latest version of the tools, so no global. json file is needed.

How do I change .NET SDK version?

In order to change default dotnet SDK version, place a global. json file in the current folder or any parent folder with the contents below. You can create the global. json file manually, or use the dotnet cli command dotnet new globaljson .

Where do I put global json files?

The global. json file in the root of your project (or even in the root of your file system as the SDK will traverse the file system until it finds one) allows defining which version of the SDK to use.

Does .NET SDK include .NET Core?

SDK information The SDK is used to build and publish . NET apps and libraries. Installing the SDK includes all three runtimes: ASP.NET Core, Desktop, and . NET.


2 Answers

If someone comes across this while not getting a .NET Core 3.0 project to open, make sure you have updated Visual Studio to the latest version. This fixed it for me when given the error below:

C:\Program Files\dotnet\sdk\2.2.402\Sdks\Microsoft.NET.Sdk.WindowsDesktop\Sdk not found. 
Check that a recent enough .NET Core SDK is installed and/or increase the version specified in global.json.
like image 89
Jason Landbridge Avatar answered Sep 27 '22 19:09

Jason Landbridge


Add

<RuntimeFrameworkVersion>2.2.3</RuntimeFrameworkVersion>

to your .csproj.

Take a look at this question and this one for more information.

like image 28
Joshit Avatar answered Sep 27 '22 18:09

Joshit