Select which .NET version to use - .NET (2024)

  • Article
  • 7 minutes to read

This article explains the policies used by the .NET tools, SDK, and runtime for selecting versions. These policies provide a balance between running applications using the specified versions and enabling ease of upgrading both developer and end-user machines. These policies enable:

  • Easy and efficient deployment of .NET, including security and reliability updates.
  • Use the latest tools and commands independent of target runtime.

Version selection occurs:

  • When you run an SDK command, the SDK uses the latest installed version.
  • When you build an assembly, target framework monikers define build time APIs.
  • When you run a .NET application, target framework dependent apps roll-forward.
  • When you publish a self-contained application, self-contained deployments include the selected runtime.

The rest of this document examines those four scenarios.

The SDK uses the latest installed version

SDK commands include dotnet new and dotnet run. The .NET CLI must choose an SDK version for every dotnet command. It uses the latest SDK installed on the machine by default, even if:

  • The project targets an earlier version of the .NET runtime.
  • The latest version of the .NET SDK is a preview version.

You can take advantage of the latest SDK features and improvements while targeting earlier .NET runtime versions. You can target different runtime versions of .NET using the same SDK tools.

On rare occasions, you may need to use an earlier version of the SDK. You specify that version in a global.json file. The "use latest" policy means you only use global.json to specify a .NET SDK version earlier than the latest installed version.

global.json can be placed anywhere in the file hierarchy. The CLI searches upward from the project directory for the first global.json it finds. You control which projects a given global.json applies to by its place in the file system. The .NET CLI searches for a global.json file iteratively navigating the path upward from the current working directory. The first global.json file found specifies the version used. If that SDK version is installed, that version is used. If the SDK specified in the global.json isn't found, the .NET CLI uses matching rules to select a compatible SDK, or fails if none is found.

The following example shows the global.json syntax:

{ "sdk": { "version": "5.0.0" }}

The process for selecting an SDK version is:

  1. dotnet searches for a global.json file iteratively reverse-navigating the path upward from the current working directory.
  2. dotnet uses the SDK specified in the first global.json found.
  3. dotnet uses the latest installed SDK if no global.json is found.

For more information about SDK version selection, see the Matching rules and rollForward sections of the global.json overview article.

Target Framework Monikers define build time APIs

You build your project against APIs defined in a Target Framework Moniker (TFM). You specify the target framework in the project file. Set the TargetFramework element in your project file as shown in the following example:

<TargetFramework>net5.0</TargetFramework>

You may build your project against multiple TFMs. Setting multiple target frameworks is more common for libraries but can be done with applications as well. You specify a TargetFrameworks property (plural of TargetFramework). The target frameworks are semicolon-delimited as shown in the following example:

<TargetFrameworks>net5.0;netcoreapp3.1;net47</TargetFrameworks>

A given SDK supports a fixed set of frameworks, capped to the target framework of the runtime it ships with. For example, the .NET 5 SDK includes the .NET 5 runtime, which is an implementation of the net5.0 target framework. The .NET 5 SDK supports netcoreapp2.0, netcoreapp2.1, netcoreapp3.0, and so on, but not net6.0 (or higher). You install the .NET 6 SDK to build for net6.0.

.NET Standard

.NET Standard was a way to target an API surface shared by different implementations of .NET. Starting with the release of .NET 5, which is an API standard itself, .NET Standard has little relevance, except for one scenario: .NET Standard is useful when you want to target both .NET and .NET Framework. .NET 5 implements all .NET Standard versions.

For more information, see .NET 5 and .NET Standard.

Framework-dependent apps roll-forward

When you run an application from source with dotnet run, from a framework-dependent deployment with dotnet myapp.dll, or from a framework-dependent executable with myapp.exe, the dotnet executable is the host for the application.

The host chooses the latest patch version installed on the machine. For example, if you specified net5.0 in your project file, and 5.0.2 is the latest .NET runtime installed, the 5.0.2 runtime is used.

If no acceptable 5.0.* version is found, a new 5.* version is used. For example, if you specified net5.0 and only 5.1.0 is installed, the application runs using the 5.1.0 runtime. This behavior is referred to as "minor version roll-forward." Lower versions also won't be considered. When no acceptable runtime is installed, the application won't run.

A few usage examples demonstrate the behavior, if you target 5.0:

  • ✔️ 5.0 is specified. 5.0.3 is the highest patch version installed. 5.0.3 is used.
  • ❌ 5.0 is specified. No 5.0.* versions are installed. 3.1.1 is the highest runtime installed. An error message is displayed.
  • ✔️ 5.0 is specified. No 5.0.* versions are installed. 5.1.0 is the highest runtime version installed. 5.1.0 is used.
  • ❌ 3.0 is specified. No 3.x versions are installed. 5.0.0 is the highest runtime installed. An error message is displayed.

Minor version roll-forward has one side-effect that may affect end users. Consider the following scenario:

  1. The application specifies that 5.0 is required.
  2. When run, version 5.0.* isn't installed, however, 5.1.0 is. Version 5.1.0 will be used.
  3. Later, the user installs 5.0.3 and runs the application again, 5.0.3 will now be used.

It's possible that 5.0.3 and 5.1.0 behave differently, particularly for scenarios like serializing binary data.

Control roll-forward behavior

The roll-forward behavior for an application can be configured in four different ways:

  1. Project-level setting by setting the <RollForward> property:

    <PropertyGroup> <RollForward>LatestMinor</RollForward></PropertyGroup>
  2. The *.runtimeconfig.json file.

    This file is produced when you compile your application. If the <RollForward> property was set in the project, it's reproduced in the *.runtimeconfig.json file as the rollForward setting. Users can edit this file to change the behavior of your application.

    { "runtimeOptions": { "tfm": "net5.0", "rollForward": "LatestMinor", "framework": { "name": "Microsoft.NETCore.App", "version": "5.0.0" } }}
  3. The dotnet command's --roll-forward <value> property.

    When you run an application, you can control the roll-forward behavior through the command line:

    dotnet run --roll-forward LatestMinordotnet myapp.dll --roll-forward LatestMinormyapp.exe --roll-forward LatestMinor
  4. The DOTNET_ROLL_FORWARD environment variable.

Precedence

Roll forward behavior is set by the following order when your app is run, higher numbered items taking precedence over lower numbered items:

  1. First the *.runtimeconfig.json config file is evaluated.
  2. Next, the DOTNET_ROLL_FORWARD environment variable is considered, overriding the previous check.
  3. Finally, any --roll-forward parameter passed to the running application overrides everything else.

Values

However you set the roll-forward setting, use one of the following values to set the behavior:

ValueDescription
MinorDefault if not specified.
Roll-forward to the lowest higher minor version, if requested minor version is missing. If the requested minor version is present, then the LatestPatch policy is used.
MajorRoll-forward to the next available higher major version, and lowest minor version, if requested major version is missing. If the requested major version is present, then the Minor policy is used.
LatestPatchRoll-forward to the highest patch version. This value disables minor version roll-forward.
LatestMinorRoll-forward to highest minor version, even if requested minor version is present.
LatestMajorRoll-forward to highest major and highest minor version, even if requested major is present.
DisableDon't roll-forward, only bind to the specified version. This policy isn't recommended for general use since it disables the ability to roll-forward to the latest patches. This value is only recommended for testing.

Self-contained deployments include the selected runtime

You can publish an application as a self-contained distribution. This approach bundles the .NET runtime and libraries with your application. Self-contained deployments don't have a dependency on runtime environments. Runtime version selection occurs at publishing time, not run time.

The restore event that occurs when publishing selects the latest patch version of the given runtime family. For example, dotnet publish will select .NET 5.0.3 if it's the latest patch version in the .NET 5 runtime family. The target framework (including the latest installed security patches) is packaged with the application.

An error occurs if the minimum version specified for an application isn't satisfied. dotnet publish binds to the latest runtime patch version (within a given major.minor version family). dotnet publish doesn't support the roll-forward semantics of dotnet run. For more information about patches and self-contained deployments, see the article on runtime patch selection in deploying .NET applications.

Self-contained deployments may require a specific patch version. You can override the minimum runtime patch version (to higher or lower versions) in the project file, as shown in the following example:

<PropertyGroup> <RuntimeFrameworkVersion>5.0.7</RuntimeFrameworkVersion></PropertyGroup>

The RuntimeFrameworkVersion element overrides the default version policy. For self-contained deployments, the RuntimeFrameworkVersion specifies the exact runtime framework version. For framework-dependent applications, the RuntimeFrameworkVersion specifies the minimum required runtime framework version.

See also

  • Download and install .NET.
  • How to remove the .NET Runtime and SDK.
Select which .NET version to use - .NET (2024)

FAQs

Which version of .NET should I use? ›

NET 6, which is the most recent LTS version. While support for . NET Core 3.1 ends in December 2022, support for . NET 6 will continue until November 2024.

Should I use .NET 3.1 or 6? ›

NET Core 3.1 has succeeded. For new projects, it's recommended to go with the newest and fastest version, . NET 6, since it is the most flexible and performance-oriented version released so far and will work on every scenario and requirement.

How do I change .NET version? ›

NET version that you just chose.
  1. In Solution Explorer, open the right-click context menu for the project that you want to change, and then choose Properties.
  2. In the left column of the Properties window, choose the Application tab. ...
  3. In the Target Framework list, choose the version that you want.
Oct 19, 2022

How do I change to .NET 6? ›

To upgrade from ASP.NET Core 5.0 to 6.0, see Migrate from ASP.NET Core 5.0 to 6.0.
  1. Prerequisites. Visual Studio. ...
  2. Update .NET SDK version in global.json. ...
  3. Update the target framework. ...
  4. Update package references. ...
  5. Delete bin and obj folders. ...
  6. Minimal hosting model. ...
  7. Update Razor class libraries (RCLs) ...
  8. Blazor.
Jun 3, 2022

Should I use .NET standard or .NET 5? ›

NET Standard 2.0 gives you the most reach while supporting . NET 5 ensures that you can leverage the latest platform features for customers that are already on . NET 5. In a couple of years, the choice for reusable libraries will only involve the version number of netX.

Is .NET 6 and .NET Core same? ›

NET 6, though, is ASP.NET Core 6, a major upgrade of Microsoft's open source framework for building modern web applications. ASP.NET Core 6 is built on top of the . NET Core runtime and allows you to build and run applications on Windows, Linux, and macOS. ASP.NET Core 6 combines the features of Web API and MVC.

Does .NET 5.0 replace .NET Core? ›

Net doesn't change the . Net Core architecture, but adds some additional benefits including Core Runtime & API Performance enhancement, and deployment flexibility. . Net 5 also supports some major sub-framework for desktop development like Entity Framework, GDI+, LINQ, and ADO.Net.

How do I determine .NET version? ›

The version of . NET Framework (4.5 and later) installed on a machine is listed in the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full. If the Full subkey is missing, then . NET Framework 4.5 or above isn't installed.

How do I convert .NET Core 3.1 to .NET 5? ›

In this article
  1. Prerequisites.
  2. Update .NET Core SDK version in global.json.
  3. Update the target framework.
  4. Delete bin and obj folders.
  5. Changes to Blazor app routing logic in 5.0.1 and further 5.x releases up to 6.0.
  6. Update Blazor WebAssembly and Blazor Server projects.
  7. Update Blazor WebAssembly projects.
Jan 4, 2023

Does .NET 6 replace .NET framework? ›

NET 6 is a replacement for the legacy . NET Framework. Microsoft has no plans to port Web Forms, Windows Communication Foundation (WCF), or Windows Workflow Foundation (WF) from .

Is .NET 6 better than .NET framework? ›

NET 6 can run on natively Mac and Linux, . NET Framework cannot and you would need a third-party runtime like Mono for that capability. . NET 6 you can compile the framework into your application so the separate framework does not need to be installed to run your app. .

Should I use .NET 5 or 6? ›

NET 6.0 has more advantages than working with the . NET 5.0 as . NET 6.0 has more improvement on the performance which also includes some major advantage as it has intelligent code editing and also it is called the fastest full-stack web framework.

How do I downgrade from .NET 6 to .NET 5? ›

Steps to reproduce:
  1. Open Visual Studio Preview 2022 Preview 6.0.
  2. Create a new C# Console App from the default template.
  3. Target the .NET 6.0 framework.
  4. Run the project.
  5. Open the project properties and change target framework to .NET 5.0.

How do I convert .NET Standard to .NET 5? ›

Migrating from the . NET Framework to . NET 5.0
  1. Create a New Folder for Your .NET Framework Project.
  2. Create a New File and Add the Code.
  3. Add the .csproj to the Existing Solution.
  4. Configure the Project File to Include Code.
  5. Add NuGet Packages.
Nov 4, 2020

How do I change my .NET framework to .NET standard? ›

To do that, complete the following steps:
  1. In Visual Studio, select Analyze and then Portability Analyzer Settings.
  2. In the General Settings window, select . NET Standard 2.0 under Target Platforms, and then choose OK.
  3. Now, open the project file containing the code that needs to target .
Nov 18, 2022

How do I convert .NET 4.8 to .NET 6? ›

Manual Migration
  1. STEP 1 – Analyze Dependencies. ...
  2. STEP 2 – Prepare for Migration. ...
  3. STEP 3 – Migrate Project File. ...
  4. STEP 4 – Fix Code & Build. ...
  5. STEP 5 – Finally Run & Test your Application on .NET 6.
Feb 8, 2022

How do I migrate from .NET 3.1 to .NET 6? ›

Steps to Migrate or Upgrade from ASP.NET Core 3.1 to . NET 6.0
  1. Step 1 – Open your current project in Visual Studio 2022. ...
  2. Step 2 – Change the Target framework to . ...
  3. Step 3 – We need to upgrade the packages that have been used to run the application.
Jan 31, 2022

What is difference between .NET 5 and .NET 6? ›

NET 5 and . NET 6 are supported on multiple operating systems, including Windows, Linux, Android, iOS /tvOS, and macOS. The only difference is that . NET 6 is further supported on Windows Arms64 and macOS Apple Silicon while .

Should I target .NET 6 or .NET Standard? ›

We recommend you target . NET Standard 2.0, unless you need to support an earlier version. Most general-purpose libraries should not need APIs outside of .

What is the difference between .NET 5.0 .NET Core and .NET Framework? ›

NET Core is written from scratch to make it a modular, lightweight, fast, and cross-platform Framework Whereas, Microsoft's Net Framework is a software development platform for building and running Windows applications.Net framework includes developer tools, programming languages, and libraries that are used to develop ...

How do I migrate from .NET Standard to .NET 6? ›

NET 6 will put you in a very good position to move to Microservices as the next step.
  1. Step 1 - Understand Your Dependencies. ...
  2. Step 2 - Upgrade the Visual Studio Project (csproj) Format. ...
  3. Step 3 - Multi-target . ...
  4. Step 4 - Fix Code Issues. ...
  5. Step 5 - High-Level Projects. ...
  6. Step 6 - Testing.
Dec 12, 2021

Is .NET Core obsolete? ›

NET Core versions no longer supported.

Is .NET Core outdated? ›

The long-term-support (LTS) version 3.1 of Microsoft . NET Core Framework is slated to go out of support on December 13th, 2022. Microsoft recommends upgrading . NET Core 3.1 applications to .

Is .NET 5 obsolete? ›

NET 5 - . NET | Microsoft Learn. This browser is no longer supported. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Is .NET 5 the same as .NET Framework? ›

NET Framework is a Microsoft product, which is maintained on Servers available in Microsoft. . NET 5 doesn't support traditional Web Forms, and Windows Workflow Foundation (WWF). .

Is .NET 5 compatible with .NET Framework? ›

For . NET Framework client developers, Windows Forms and WPF are supported with . NET 5.0.

Is .NET Framework 4.8 the latest version? ›

NET Framework 4.8. 1 is included in the latest version of Visual Studio, Visual Studio 2022 17.3. .

Is .NET 4.8 still supported? ›

NET Framework 4.8 is the latest version of . NET Framework and will continue to be distributed with future releases of Windows. As long as it is installed on a supported version of Windows, . NET Framework 4.8 will continue to also be supported.

How to check the .NET version in CMD? ›

You can also press the Windows key + R shortcut, then enter "cmd" in the Run dialog box. Then, press CTRL + SHIFT + ENTER to open the Command Prompt. Run The Initial Check . Net Version Command: Type in reg query "HKLM\SOFTWARE\Microsoft\Net Framework Setup\NDP" /s to run the initial check.

Is .NET Core 3.1 compatible with .NET 5? ›

You can. Just upgrade all your project dependencies via NuGet to latest stable version and it will let you upgrade your . Net Core 3.1 to . Net 5.

Is .NET 5 the same as .NET Core? ›

NET 5 is the next major release of . NET Core following 3.1. We named this new release .

Is NET Core 3.1 deprecated? ›

. NET Core 3.1 will reach end of support on December 13, 2022. After that date, Microsoft will no longer provide servicing updates or technical support for . NET Core 3.1.

Why can't I select different C# version? ›

If you're using the latest version of Visual Studio 2019, C#, you may not see the option to change the C# language version of your project. This is a new change in Visual Studio 2019/. NET Core 3.0. The new C# compiler chooses the default version based on your .

How do I know which version of C# is being used? ›

Click on the Properties tab. From properties window select Build option. In that click on the Advance button. There you will find out the language version.

Can I use C# 9 with .NET framework? ›

NET Standard 2.1, Microsoft has announced tightly coupled C# and . NET version releases. So, C# 9 will be the default and latest language version for . NET 5.

Is .NET 6 compatible with .NET Framework? ›

The compatibility of . NET Framework technologies has stayed consistent between . NET 5 and . NET 6 (although WinForms has a few more breaking changes in .

Which .NET Framework should I use Windows 10? ›

The . NET Framework 4.6. 2 is the latest supported . NET Framework version on Windows 10 1507 and 1511.

What is difference between .NET and .NET Framework? ›

Some key differences include: . NET is cross-platform and runs on Linux, macOS, and Windows. . NET Framework only runs on Windows.

Does .NET 6 replace .NET 5? ›

NET 6 towards the end of 2021 gives you a target to aim for, with more features and increased cross-platform support. Code built for . NET 5 will run on . NET 6, and you can update it to take advantage of the new release's additional options and APIs.

How much faster is .NET 6? ›

The gist is: . NET 6 with PGO enabled may bring you: +30–40% speed on tight loops & cache-friendly logic. +15% for an average code that doesn't depend on networking & IO.

Why should I upgrade to .NET 5? ›

In addition to improvements in costs, performance, and scalability, upgrading to . NET 5 supports the latest C# version and allows our client to utilize the latest Entity Framework (EF) Core 3 package. EF Core 3's benefits include: Faster reading and writing of data from and to the database.

Why can't I select a different C# version? ›

If you're using the latest version of Visual Studio 2019, C#, you may not see the option to change the C# language version of your project. This is a new change in Visual Studio 2019/. NET Core 3.0. The new C# compiler chooses the default version based on your .

How do I change my dotnet version in Windows? ›

How to change the . NET Framework Version in Visual Studio
  1. In your Solution Explorer, right-click your project and select Properties.
  2. In Properties, go to the Application option on the side menu.
  3. Locate the Target framework dropdown and select the framework version you need.
Apr 6, 2020

How do I change the .NET version in Visual Studio 2022? ›

In Visual Studio:
  1. Right-click on your project.
  2. Select Properties.
  3. Select the Application tab.
  4. Change the Target Framework to the desired framework.

Can I use C# 8 with .NET framework? ›

Yes, C# 8 can be used with the . NET Framework and other targets older than . NET Core 3.0/. NET Standard 2.1 in Visual Studio 2019 (or older versions of Visual Studio if you install a NuGet package).

Does .NET 4.8 support C# 8? ›

NET Framework 4.8 will not. This means that the types required to use these features won't be available on . NET Framework 4.8." "For this reason, using C# 8.0 is only supported on platforms that implement .

How do I downgrade .NET 6 to .NET 5? ›

Steps to reproduce:
  1. Open Visual Studio Preview 2022 Preview 6.0.
  2. Create a new C# Console App from the default template.
  3. Target the .NET 6.0 framework.
  4. Run the project.
  5. Open the project properties and change target framework to .NET 5.0.

How can I update my net core 3.1 to .NET 5? ›

In this article
  1. Prerequisites.
  2. Update .NET Core SDK version in global.json.
  3. Update the target framework.
  4. Delete bin and obj folders.
  5. Changes to Blazor app routing logic in 5.0.1 and further 5.x releases up to 6.0.
  6. Update Blazor WebAssembly and Blazor Server projects.
  7. Update Blazor WebAssembly projects.
Jan 4, 2023

How do I upgrade from .NET 5 to .NET 6? ›

NET 5. In Visual Studio, simply right click on your project in Solution Explorer and choose Properties. Under Application > General > Target framework, choose . NET 6.0.

How to select net Framework version in Visual Studio? ›

To change the target Framework
  1. In Visual Studio, in Solution Explorer, select your project. ...
  2. On the menu bar, select File, Open, File. ...
  3. In the project file, locate the entry for the target Framework version. ...
  4. Change the value to the Framework version you want, such as v3. ...
  5. Save the changes and close the editor.
Nov 23, 2021

How to change the version of asp net c#? ›

My workarounds was as follows: File/New/ASP.NET Web Application.
...
This is such an easy option, it is worth trying first.
  1. Right click your project and select Properties.
  2. Click the Build tab.
  3. The build tab has an Advanced... button at the very bottom.
  4. This opens up the Advanced Build Settings as shown below. Select C# 6.0.

Should I use .NET Standard or .NET 5? ›

NET Standard 2.0 gives you the most reach while supporting . NET 5 ensures that you can leverage the latest platform features for customers that are already on . NET 5. In a couple of years, the choice for reusable libraries will only involve the version number of netX.

Is .NET Standard 2.0 compatible with .NET 5? ›

NET Framework 4.6. 1 as supporting . NET Standard 1.5 through 2.0, there are several issues with consuming . NET Standard libraries that were built for those versions from .
...
Select . NET Standard version.
.NET implementationVersion support
.NET and .NET Core1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0
7 more rows
Nov 8, 2022

Is .NET framework 4.8 compatible with standard? ›

NET Framework 4.8 will remain on . NET Standard 2.0 rather than implement . NET Standard 2.1. . NET Core 3.0 as well as upcoming versions of Xamarin, Mono, and Unity will be updated to implement .

Top Articles
Latest Posts
Article information

Author: Gov. Deandrea McKenzie

Last Updated:

Views: 6670

Rating: 4.6 / 5 (66 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Gov. Deandrea McKenzie

Birthday: 2001-01-17

Address: Suite 769 2454 Marsha Coves, Debbieton, MS 95002

Phone: +813077629322

Job: Real-Estate Executive

Hobby: Archery, Metal detecting, Kitesurfing, Genealogy, Kitesurfing, Calligraphy, Roller skating

Introduction: My name is Gov. Deandrea McKenzie, I am a spotless, clean, glamorous, sparkling, adventurous, nice, brainy person who loves writing and wants to share my knowledge and understanding with you.