Switch between dotnet core SDK versions
You can do this with a global.json
file in the root of your project:
- Verify the list of SDKs on your machine:
dotnet --list-sdks
You'll see a list like this.
2.1.100 [C:\Program Files\dotnet\sdk]
2.1.101 [C:\Program Files\dotnet\sdk]
2.1.103 [C:\Program Files\dotnet\sdk]
2.1.104 [C:\Program Files\dotnet\sdk]
[...lines omitted...]
2.1.601 [C:\Program Files\dotnet\sdk]
2.2.101 [C:\Program Files\dotnet\sdk]
3.0.100-preview3-010431 [C:\Program Files\dotnet\sdk]
- Create a folder to be the root of your project, where you are going to run
dotnet new
. - In that folder, run this command:
dotnet new globaljson
The result will look something like this:
{
"sdk": {
"version": "3.0.100-preview3-010431"
}
}
- In
version
, replace the3.0.100-preview3-010431
with the version you prefer from the--list-sdks
list. For example:
{
"sdk": {
"version": "2.2.101"
}
}
- Run
dotnet --version
to verify. You should see:
2.2.101
- Run the appropriate
dotnet new
commands to create your project.
How to make dotnet core select a lower version?
To list all the versions of dotnet core installed in the system, open the command prompt and type the following command:
dotnet --info
If you want to know the specific version used for running the application, go to the folder location, and type cmd
in the address bar at the top to open command prompt. Then type this in command prompt.
dotnet --version
If you want to change this version to some other version installed in the system, type the following in the command prompt.
dotnet new globaljson --sdk-version 2.2.100 --force
Here, I want to use 2.2.100
. This will create a global.json file. This will tell Visual Studio which version of .NET Core to use.
This is the content of global.json file.
{
"sdk": {
"version": "2.2.100"
}
}
By following this, you can switch between .NET Core versions. Otherwise, Visual Studio will only take the latest version installed.
Further Reading:
dotnet
commanddotnet new
command
how to call a specific dotnet core version
Changing it in global.json is the way to set the current runtime version in terms of what you are trying to do. Even if there were a way in the command level it should only create a global.json file with the same configuration and then make the new app. The reason I say "should" is because there is already a way to do this, it wouldn't make sense to have a second way.
If updating the global.json file and then creating new projects doesn't work for you, then that is the bug you need to focus on fixing. I wouldn't advise trying to move away from global.josn. I have just tested this out. The generated templates are based on the respective version. If this isn't working, update your question with the exact errors.
Changing the default version of the Net Core SDK on Yeoman
yo aspnet project is a little bit "dead". If you check repository on github, you will find that last update was 9 months ago.
Just use official dotnet new scaffolding tool, that is part of .NET Core CLI.
How to change the dotnet SDK version for the particular build?
Stupid me, it is really simple and explained here - https://learn.microsoft.com/en-us/dotnet/core/versions/selection#the-sdk-uses-the-latest-installed-version
Creating global.json with the following content solved my issue:
{
"sdk": {
"version": "5.0.406"
}
}
dotnet cli how to create project using previous sdk/framework?
Based on the docs on how to select the .NET version to use:
Create a global.json
file in your new project folder with the following content (for .net core 2.2.203 - change to required version):
{
"sdk": {
"version": "2.2.203"
}
}
From a command line cd
into that folder and run:dotnet new choose-template-name
Running any dotnet CLI command in this folder and sub-folders, will use the specified SDK.
Make sure the SDK is installed first, of course.
Select the .NET Core version to use
The problem was in the publish profile. My profile was created when the project was targeted to .NET Core 2.1. Later I migrated to .NET Core 2.2 and maked according change in the existing profile. Obviously that change was not sufficient. To solve the problem I have deleted exiting profile and created new one targeted to .NET Core 2.2.
Related Topics
How to Expand a String That Contains C# Literal Expressions at Runtime
How to Highlight Wrapped Text in a Control Using the Graphics
Unique Ways to Use the Null Coalescing Operator
Current Possibilities for Tracing Program Flow in C#
How to Use Linq Distinct() with Multiple Fields
How Is Gethashcode() Implemented for Int32
Dynamically Switch Wcf Web Service Reference Url Path Through Config File
Resources for Learning C# Excel Interop
How to Change the Button Text for 'Yes' and 'No' Buttons in the Messagebox.Show Dialog
Udp Hole Punching Implementation
What Is C# Analog of C++ Std::Pair
How to Bind an Enum to a Dropdownlist Control in ASP.NET
How to Access Elements of a Jarray (Or Iterate Over Them)
In C# What Category Does the Colon ":" Fall Into, and What Does It Really Mean