Reputation: 2784
I recently installed VS 2017 RC and then automatically my dotnet version pointed to 1.0.0-preview4-004233
. Due to that whenever I create a new project using command dotnet new -t Console
I cannot see project.json
though I see .csproj
file.
When I check dotnet versions available on my machine at - C:\Program Files\dotnet\sdk
I see multiple versions available.
Is there any way to switch dotnet core back to an earlier version - 1.0.0-preview2-003133
from 1.0.0-preview4-004233
without uninstalling.
Upvotes: 147
Views: 172735
Reputation: 3245
The "Set" answer is completely correct. Anyhow if you are looking for another straightforward workaround you can use the -f|--framework
parameter and set the value to TFM( Target framework moniker)
.
For example: dotnet new webapi -f net6.0
the list of TFM are as bellow :
You can explore all the options on Microsoft Document
Upvotes: 2
Reputation: 243
You can check in global.json
file
Run the following command
dotnet --list-sdks
You will see the results
2.2.110 [C:\Program Files\dotnet\sdk]
5.0.103 [C:\Program Files\dotnet\sdk]
Upvotes: -1
Reputation: 4343
For ubuntu only (ex: force version 6.0 instead of 7.0) :
wget https://dot.net/v1/dotnet-install.sh
chmod +x dotnet-install.sh
./dotnet-install.sh --channel 6.0
mv ~/.dotnet/sdk/7.0.200/ /tmp/unusedDotnetVersion # Manually remove other dotnet versions
Upvotes: 0
Reputation: 641
If you want to create a new project using a specific version you can go to this directory 'C:\Program Files\dotnet\sdk' then add an underscore to newer version (all of them) of dotnet that you don't want (only the newer ones is enough) then create your project.
Upvotes: 4
Reputation: 161
When we install each dotnet core SDK on OS, the each project can use SDKs version separately. Because the SDK have global installation. We can configuration each project settings by create global.json
via this command:
dotnet new globaljson
and finally selected the correct version.
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.Step-by-Step: https://stackoverflow.com/a/42078060/14557383
Upvotes: 11
Reputation: 945
Dotnet usually uses the latest SDK version, unless it finds a global.json file that tells it to do otherwise. The explanation by microsoft
dotnet looks for the file in the working directory (not necessarily the project or solution directory), and if it can't find one it starts searching upwards from there. documentation
An easy way to create a global.json file would be to run dotnet new globaljson --sdk-version 1.0.0-preview2-003133
in the directory of your project.
create a global.json from the cli
Upvotes: 16
Reputation: 49809
You can do this with a global.json
file in the root of your project:
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]
dotnet new
.dotnet new globaljson
The result will look something like this:
{
"sdk": {
"version": "3.0.100-preview3-010431"
}
}
version
, replace the 3.0.100-preview3-010431
with the version you prefer from the --list-sdks
list. For example:{
"sdk": {
"version": "2.2.101"
}
}
dotnet --version
to verify. You should see:2.2.101
dotnet new
commands to create your project.Upvotes: 274