I have a .NET Core 5 console application:
<TargetFramework>net5.0</TargetFramework>
When I compile it in VS2022, it seems to use .NET Core 7 to do so, because I see this in the build output:
1>C:\Program Files\dotnet\sdk\7.0.100-rc.2.22477.23\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(257,5):
message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
How can I tell Visual Studio to use .NET Core 5 to compile this project?
.NET 5 is installed on my machine:
PS B:\...> dotnet --list-sdks
5.0.413 [C:\Program Files\dotnet\sdk]
7.0.100-rc.2.22477.23 [C:\Program Files\dotnet\sdk]
Yes, I'm aware that .NET Core 5 is outdated.
Exact version is Visual Studio 2022 17.4.0 Preview 6
SLN file:
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33027.239
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCore5Console", "ConsoleNetCore5\NetCore5Console.csproj", "{43DE576A-1052-4AC5-B612-D88D9D6624B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{43DE576A-1052-4AC5-B612-D88D9D6624B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43DE576A-1052-4AC5-B612-D88D9D6624B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EF895EC5-66AD-4B5A-ACFF-594C848D2311}
EndGlobalSection
EndGlobal
CSPROJ file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
</Project>
Program.cs
using System;
using System.Text.RegularExpressions;
namespace ConsoleNetCore5
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
CodePudding user response:
Set a global.json
file along side your solution file specifying which SDK version you want to use.
{
"sdk": {
"version": "5.0.413",
"rollForward": "latestFeature"
}
}
https://learn.microsoft.com/en-us/dotnet/core/tools/global-json