- 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:
dotnet
searches for a global.json file iteratively reverse-navigating the path upward from the current working directory.dotnet
uses the SDK specified in the first global.json found.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:
- The application specifies that 5.0 is required.
- When run, version 5.0.* isn't installed, however, 5.1.0 is. Version 5.1.0 will be used.
- 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:
Project-level setting by setting the
<RollForward>
property:<PropertyGroup> <RollForward>LatestMinor</RollForward></PropertyGroup>
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 therollForward
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" } }}
The
dotnet
command's--roll-forward <value>
property.(Video) .NET Core and .NET Framework - what to choose? | Desktop and .NET Core 101 [1 of 3]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
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:
- First the
*.runtimeconfig.json
config file is evaluated. - Next, the
DOTNET_ROLL_FORWARD
environment variable is considered, overriding the previous check. - 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:
Value | Description |
---|---|
Minor | Default 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. |
Major | Roll-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. |
LatestPatch | Roll-forward to the highest patch version. This value disables minor version roll-forward. |
LatestMinor | Roll-forward to highest minor version, even if requested minor version is present. |
LatestMajor | Roll-forward to highest major and highest minor version, even if requested major is present. |
Disable | Don'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.
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? ›- In Solution Explorer, open the right-click context menu for the project that you want to change, and then choose Properties.
- In the left column of the Properties window, choose the Application tab. ...
- In the Target Framework list, choose the version that you want.
- Prerequisites. Visual Studio. ...
- Update .NET SDK version in global.json. ...
- Update the target framework. ...
- Update package references. ...
- Delete bin and obj folders. ...
- Minimal hosting model. ...
- Update Razor class libraries (RCLs) ...
- Blazor.
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.
How do I convert .NET Core 3.1 to .NET 5? ›- Prerequisites.
- Update .NET Core SDK version in global.json.
- Update the target framework.
- Delete bin and obj folders.
- Changes to Blazor app routing logic in 5.0.1 and further 5.x releases up to 6.0.
- Update Blazor WebAssembly and Blazor Server projects.
- Update Blazor WebAssembly projects.
Open the solution with Visual Studio, right-click on the project, click on “Properties”, and on “Target Framework” change from “. NET 3.1” to “. NET 5”: Do the same for the other project's layers, including the unit tests projects.
How do I move from .NET 5 to .NET 6? ›
Migrating from .
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.
NET Core 3.1 was originally released on December 3, 2019 and is supported for three years. But the actual end of support day will be the closest Patch Tuesday starting that date, which is December 13, 2022.
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. .
How do I change my .NET framework to .NET standard? ›- In Visual Studio, select Analyze and then Portability Analyzer Settings.
- In the General Settings window, select . NET Standard 2.0 under Target Platforms, and then choose OK.
- Now, open the project file containing the code that needs to target .
NET Framework 4.8 is available on Windows Update (WU) and on Windows Server Update Service (WSUS). It will be offered as a recommended update on Windows Update. A recommended update may be installed automatically on all supported platforms based on your computer settings on Windows Update.
How do I convert .NET 4.8 to .NET 6? ›- STEP 1 – Analyze Dependencies. ...
- STEP 2 – Prepare for Migration. ...
- STEP 3 – Migrate Project File. ...
- STEP 4 – Fix Code & Build. ...
- STEP 5 – Finally Run & Test your Application on .NET 6.
- Step 1 – Open your current project in Visual Studio 2022. ...
- Step 2 – Change the Target framework to . ...
- Step 3 – We need to upgrade the packages that have been used to run the application.
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.
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 .
How do I migrate from .NET Standard to .NET 6? ›- Step 1 - Understand Your Dependencies. ...
- Step 2 - Upgrade the Visual Studio Project (csproj) Format. ...
- Step 3 - Multi-target . ...
- Step 4 - Fix Code Issues. ...
- Step 5 - High-Level Projects. ...
- Step 6 - Testing.
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.
Should I use .NET or .NET Core? ›NET Core is faster than . NET Framework because the architecture of . NET Core is written or restructured from scratch to make it a modular, lightweight, fast, and cross-platform Framework. The Applications require technologies like workflow, webforms or WCF that are not present in .
Is .NET 6 backwards compatible with .NET 5? ›NET 5/6/7 are cross-platform, and do not include all the windows-specific code. It can be installed on linux/mac/windows. NET Standard is a set of interfaces that help to guarantee cross-compatibility no matter whether you are running NET Framework or NET 5/6/7.
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.0 and .NET Core same? ›NET 5 is the next major release of . NET Core following 3.1. We named this new release .
What is the difference between .NET 5.0 and .NET Framework? ›NET Core supports multiple platforms like Windows, macOS & Linux whereas . NET Framework-based applications support only the Windows platforms.
What is the difference between .NET 5 and .NET 6? ›Platforms
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 .
NET Framework 4.8. 1 is included in the latest version of Visual Studio, Visual Studio 2022 17.3. .
How to check the .NET Framework version of an application in Visual Studio? ›- In Solution Explorer, open the context menu for the project that you want to change, and then choose Properties.
- In the left column of the Properties window, choose the Application tab.
- In the Target Framework list, you will see the current version of . NET framework on the project.
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.
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.
What is the difference between .NET Core 3.1 and .NET Core 5? ›Unlike the jump between ASP.NET and ASP.NET Core, there isn't a major difference between ASP.NET Core 3.1 and ASP.NET Core for . NET 5. Well, certainly not for the startup anyways. ASP.NET Core applications are still built in Console Applications.
Is .NET 5.0 backwards compatible? ›NET Framework 4.5 and later versions are backward-compatible with apps that were built with earlier versions of the . NET Framework. In other words, apps and components built with previous versions will work without modification on the . NET Framework 4.5 and later versions.
How to change target framework from .NET standard to .NET Core? ›...
1 Answer
- Install upgrade-assistant: dotnet tool install -g upgrade-assistant.
- Go to your solution folder.
- Run the assistant: upgrade-assistant upgrade your-project-name.csproj.
- Follow the steps in the assistant, it's really straight-forward.
NET 5 is installed with Visual Studio 2019 16.11 or 16.9 or 16.7, depending upon the installed workloads. "Starting with the June 2022 servicing update for Visual Studio 2019 16.11 and Visual Studio 2019 16.9, the .
Is .NET 5 the same as .NET 5? ›NET 5.0 is the next major release of . NET Core following 3.1. Microsoft named this new release .
Is .NET 3.5 still needed? ›Starting with Windows 10 version 1809 and Windows Server 2019, . NET Framework 3.5 SP1 is defined as a standalone product and no longer as a component of the operating system (OS). As a product, . NET 3.5 SP1 will receive 5 years of mainstream support followed by 5 years of extended support.
Is .NET 3.0 still supported? ›This browser is no longer supported. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
What version of C# does .NET Core 3.1 Use? ›C# version | VS version | .NET version |
---|---|---|
2019 (v16.3) | .NET Core 3.0 | |
2019 (v16.4) | .NET Core 3.1 | |
9.0 | 2019 (v16.8) | .NET 5 |
10.0 | 2022 | .NET 6 |
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 backwards compatible with .NET Framework? ›
New Nuget package
Net 6 release is as backwards compatible as possible, there are some breaking changes that we couldn't avoid during development. This means that the upgrading from . Net Framework to . Net 6 is a bit more involved than just updating the Nuget.
The compatibility of . NET Framework technologies has stayed consistent between . NET 5 and . NET 6 (although WinForms has a few more breaking changes in .
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 to set .NET version in Visual Studio? ›- Right-click on your project.
- Select Properties.
- Select the Application tab.
- Change the Target Framework to the desired framework.
- Create a New Folder for Your .NET Framework Project.
- Create a New File and Add the Code.
- Add the .csproj to the Existing Solution.
- Configure the Project File to Include Code.
- Add NuGet Packages.
Use dotnet tool update --global dotnet-ef to update the global tools to the latest available version. If you have the tools installed locally in your project use dotnet tool update dotnet-ef . Install a specific version by appending --version <VERSION> to your command.
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.
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 select .NET framework in Visual Studio 2022? ›- In Visual Studio, in Solution Explorer, select your project. ...
- On the menu bar, select File, Open, File. ...
- In the project file, locate the entry for the target Framework version. ...
- Change the value to the Framework version you want, such as v3. ...
- Save the changes and close the editor.
How do I downgrade from .NET 6 to .NET 5? ›
- Open Visual Studio Preview 2022 Preview 6.0.
- Create a new C# Console App from the default template.
- Target the .NET 6.0 framework.
- Run the project.
- Open the project properties and change target framework to .NET 5.0.
- In your Solution Explorer, right-click your project and select Properties.
- In Properties, go to the Application option on the side menu.
- Locate the Target framework dropdown and select the framework version you need.
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? ›...
Select . NET Standard version.
.NET implementation | Version support |
---|---|
.NET and .NET Core | 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0 |
Microsoft designed the . NET Framework so that multiple versions of the framework can be installed and used at the same time. This means that there will be no conflict if multiple applications install different versions of the . NET framework on a single computer.
Can I install an older version of Net Framework? ›Because the 4. x versions of the . NET Framework are in-place updates, you cannot install an earlier version of the . NET Framework 4.
Can you use Entity Framework with .NET core? ›NET Framework, as Entity Framework 6 doesn't support . NET Core. If you need cross-platform features you will need to upgrade to Entity Framework Core. The recommended way to use Entity Framework 6 in an ASP.NET Core application is to put the EF6 context and model classes in a class library project that targets .