I am on Windows 10. I have both .net core
2.1 and 5.0 installed on my machine. I can see them in path C:\Program Files\dotnet\sdk
. Also both of them are present in the result of the following command:
dotnet --info
When running dotnet --version
on the prompt I see version 5.0.401. I have some backward compatiblites, so I need to use .net core 2.1
only.
How can I make .net core 2.1
as default? Please consider that I mean cli
. On the other hand, I want .net core 2.x
be run everytime I type dotnet
in the terminal.
UPDATE
- re-installing .net sdk 2.1 didn't help
- when in the windows 'settings => Apps & features' search for
core
I see only2.1
. However, when searching for SDK, I can see both.Net Core SDK 2.1
and.NET SDK 5.0
. Do you remember thatcore
has been removed from the product name? I tried to remove 5.0 but got message: .NET SDK 5.0 was installed with Visual Studio. So use Visual Studio Modify. But Visual Studio modify page does not have such a option. It only allows .Net Core 2.1 removal.
CodePudding user response:
You can use a global.json file to specify the version you would like to use. You can do so within the folder where your project is, or add one on a higher level to for instance have it work for your entire code
folder.
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": "2.1.30" } }
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, see Select the .NET version to use.
CodePudding user response:
All .NET versions get installed to the same location. When you type dotnet
, the latest SDK/Runtime/host is used (unless you override it per-project).
So, if you really want dotnet
to mean .NET Core 2.1 and nothing else, the right way to do that seem to be to uninstall newer versions such as .NET 5.