Why is dotnet build not using the specified SDK on global.json? - .net-core

I have a global.json with the following contents
{
"sdk": {
"version": "2.2.300"
}
}
This is the output of dotnet --list-sdks
2.0.3 [C:\Program Files\dotnet\sdk]
2.1.105 [C:\Program Files\dotnet\sdk]
2.1.300 [C:\Program Files\dotnet\sdk]
2.2.300 [C:\Program Files\dotnet\sdk]
This is the output of donet --list-runtimes
Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.3 [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.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Yet when I do dotnet build I get the following error
Microsoft (R) Build Engine version 16.1.76+g14b0a930a7 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Program
Files\dotnet\sdk\2.1.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5):
error : The current .NET SDK does not support targeting .NET Core 2.2.
Either target .NET Core 2.1 or lower, or use a version of the .NET SDK
that supports .NET Core 2.2.
[C:\solutionfolder\projectfolder\Project.csproj]
C:\Program
Files\dotnet\sdk\2.1.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5):
error : The current .NET SDK does not support targeting .NET Core 2.2.
Either target .NET Core 2.1 or lower, or use a version of the .NET SDK
that supports .NET Core 2.2.
[C:\solutionfolder\projectfolder\Project.csproj]
Build FAILED.
C:\Program
Files\dotnet\sdk\2.1.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5):
error : The current .NET SDK does not support targeting .NET Core 2.2.
Either target .NET Core 2.1 or lower, or use a version of the .NET SDK
that supports .NET Core 2.2.
[C:\solutionfolder\otherprojectfolder\OtherProject.csproj]
C:\Program
Files\dotnet\sdk\2.1.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5):
error : The current .NET SDK does not support targeting .NET Core 2.2.
Either target .NET Core 2.1 or lower, or use a version of the .NET SDK
that supports .NET Core 2.2.
[C:\solutionfolder\otherprojectfolder\OtherProject.csproj]
0 Warning(s)
2 Error(s)
I need help, this is driving me nuts

Ok, found the solution, it seems this Environment System Variable
MSBuildSDKsPath was pointing to the .NET Core 2.1.300 Sdks folder, removing that variable addressed the problem.

Related

How to install specified framework in Teamcity server as a build step

I have dotnet project built using dotnetcore v2.0 which was working fine in Teamcity pipeline.
I have updated the project to use dotnetcore v3.0 and re-run the Teamcity build.
now I am getting the error
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '3.1.0' was not found.
- The following frameworks were found:
1.0.3 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.0.0 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.0.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.2.3 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
5.0.10 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
How to install the dotnetcore v3.0 in the build step.
I am not sure TeamCity will do it for you. You will need to go install it on the build agent.

What is the meaning of 'Host (useful for support)' in output of 'dotnet --info'

Output from dotnet --info:
.NET Core SDK (reflecting any global.json):
Version: 3.1.416
Commit: 8d3765c609
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19044
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.416\
Host (useful for support):
Version: 5.0.13
Commit: b3afe99225
.NET SDKs installed:
3.1.416 [C:\Program Files\dotnet\sdk]
5.0.404 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
What does 'Host (useful for support) Version 5.0.13' mean here?
I have a global.json to specify that I want to use 3.1.416:
global.json:
{
"sdk": {
"version": "3.1.416",
"rollForward": "disable"
}
}
But this 'Host (useful for support)' seems to indicate that I am using 5.0.13 after all.
So, you already knew that on a single machine multiple .NET Core SDK can be installed, like 3.1 and 5.0 on yours.
They both install to a common place C:\Program Files\dotnet\sdk, but there is a single dotnet.exe executable, which usually comes from the newest .NET Core SDK installation, which is the "Host" in your context.
When you set the desired SDK version in global.json, the 5.0 Host is smart enough to redirect all actual commands (like dotnet build) to utilize the 3.1 SDK bits.

.net standard compatibility

According to this page, .NET Core 2.1.15 is compatible with .NET standard 2.0. We have an application that had projects with the above versions and it worked, but when we loaded it again recently, we received the following error:
The current .NET SDK does not support targeting .NET Standard 2.0. Either target .NET Standard 1.6 or lower, or use a version of the .NET SDK that supports .NET Standard 2.0.
Our app MUST use SDK ver 2.1.803 (defined in global.json) and .net core 2.1.15 (Also specified in appsettings).
Here are my installed .net versions:
C:\Windows\system32>dotnet --info .NET Core SDK (reflecting any
global.json): Version: 2.2.109 Commit: 586f23c400
Runtime Environment: OS Name: Windows OS Version: 10.0.17134
OS Platform: Windows RID: win10-x64 Base Path: C:\Program
Files\dotnet\sdk\2.2.109\
Host (useful for support): Version: 2.2.7 Commit: b1e29ae826
.NET Core SDKs installed:
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.505 [C:\Program Files\dotnet\sdk]
2.1.511 [C:\Program Files\dotnet\sdk]
2.1.803 [C:\Program Files\dotnet\sdk]
2.2.109 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.9
[C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.15 [C:\Program
Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.7 [C:\Program
Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.9 [C:\Program
Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.15 [C:\Program
Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.7 [C:\Program
Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App
2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.9 [C:\Program
Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App
2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.7 [C:\Program
Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
We tried the following:
Uninstalled all .net core and sdk versions that were not 2.1.15 and 2.1.803 respectively,
Updated VS 2017 to the latest version
Downgraded to .NET Standard 1.6, but we had a lot of features that were not available to this version
Added .NET Standard nuget package back and updated all .NET Standard projects to use it, but received a similar message: SDK incompatibility.
So my questions are:
How do I know what .NET standard version is installed on my machine?
Did anyone experience this issue before?
Thanks
Alex
VS 2019 resolved the issue. It is the only IDE to work with .net Core 2.1.15 and SDK 2.1.803

dotnet SDK 2.2.104 don't compile .NET Core 2.2

I have a .NET Sdk version 2.1 and lower.
I installed sdk2.2 and sdk3.
I removed sdk3
Now, the VS17 build and test my solution successfully.
But from the command line, with dotnet-cli, I can't compile the solution, because he says he is sdk2.1.
dotnet build:
C:\Program Files\dotnet\sdk\2.1.500\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 2.2. Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 2.2. [C:\Users\.......\WebApi.csproj]
Build FAILED.
dotnet --info:
.NET Core SDK (reflecting any global.json):
Version: 2.2.104
Commit: 73f036d4ac
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.104\
Host (useful for support):
Version: 2.2.2
Commit: a4fd7b2c84
.NET Core SDKs installed:
2.1.500 [C:\Program Files\dotnet\sdk]
2.2.104 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
WebApi.csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
.
.
.
</PropertyGroup>
</Project>
Thanks to livarcocc, we know the issue is in MSBuildSDKsPath environment variable, who still points to sdk2.1.
For fix the problem, we need to retarget the MSBuildSDKsPath to the SDK version we want, or completely remove this variable.
Before:
set MSBuildSDKsPath
MSBuildSDKsPath=C:\Program Files\dotnet\sdk\2.1.500\Sdks
After:
set MSBuildSDKsPath
MSBuildSDKsPath=C:\Program Files\dotnet\sdk\2.2.104\Sdks

Difference between .NET Core SDK and TargetFramework versions

I don't really understand what is the difference between the dotnet sdk version and the TargetFramework version specified in my csproj file.
For example, my current project is using <TargetFramework>netcoreapp2.1</TargetFramework> version, but dotnet --version command returns 2.2.100. So the major version is the same, but the minor differs by 1.
Is it backwards compatible and netcoreapp2.1 apps can run on newer versions of dotnet sdk or something completely different?
dotnet --info:
.NET Core SDK (reflecting any global.json):
Version: 2.2.100
Commit: b9f2fa0ca8
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.100\
Host (useful for support):
Version: 2.2.0
Commit: 1249f08fed
.NET Core SDKs installed:
2.2.100 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

Resources