Whether you're just starting with .NET development or troubleshooting an existing project, one of the first things you'll need to know is what versions of the .NET SDK and runtime are installed on your machine. This information becomes crucial when dealing with compatibility issues, setting up new projects, or collaborating with team members who might be using different versions.
The Quick Commands You Need
Fortunately, Microsoft made this process straightforward with a few simple commands that work across Windows, macOS, and Linux.
Checking Installed SDKs
To see all .NET SDKs installed on your system, open your terminal or command prompt and run:
dotnet --list-sdks
This command will show you something like:
6.0.405 [C:\Program Files\dotnet\sdk]
7.0.102 [C:\Program Files\dotnet\sdk]
8.0.100 [C:\Program Files\dotnet\sdk]
Each line shows the SDK version followed by its installation path. The SDK is what you need for developing .NET applications - it includes the compiler, tools, and libraries necessary to build your projects.
Checking Installed Runtimes
To see all .NET runtimes on your system, use:
dotnet --list-runtimes
You'll get output similar to:
Microsoft.AspNetCore.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
The runtime is what's needed to actually run .NET applications. You might notice different types of runtimes listed - these serve different purposes:
- Microsoft.NETCore.App: The base runtime for console and server applications
- Microsoft.AspNetCore.App: Additional components for web applications
- Microsoft.WindowsDesktop.App: Components for Windows desktop applications (WPF, WinForms)
The All-in-One Command
If you want a comprehensive overview of your .NET installation, there's a single command that provides everything:
dotnet --info
This command gives you detailed information about your entire .NET environment, including:
- The currently active SDK version
- All installed SDKs and runtimes
- Runtime environment details
- Operating system information
The output is quite verbose, but it's incredibly useful when you need to provide environment details for bug reports or when working with support teams.
Understanding the Output
When you run these commands, you might see multiple versions installed. This is completely normal and actually beneficial - .NET supports side-by-side installations, meaning you can have multiple versions coexisting without conflicts.
The .NET CLI will automatically select the appropriate SDK version based on your project's configuration. If you have a global.json
file in your project, it will use the SDK version specified there. Otherwise, it defaults to the latest installed version.
Common Scenarios
Starting a New Project
Before creating a new .NET project, check your available SDKs to ensure you're using the version you want. If you need a specific version for compatibility reasons, you can specify it in a global.json
file.
What If Nothing Is Installed?
If you run these commands and get a message like "command not found" or "dotnet is not recognized," it means the .NET CLI isn't installed on your system. You can download it from Microsoft's official .NET website.
Keeping Track of Versions
Different projects might target different .NET versions, and that's okay. The beauty of .NET's side-by-side installation model is that you can maintain multiple projects with different framework requirements without conflicts.
If you find yourself frequently switching between different .NET versions for various projects, consider keeping a simple text file or note with the versions each project requires. This can save time when you return to older projects months later.
Final Thoughts
These simple commands are among the most useful in any .NET developer's toolkit. Whether you're debugging a mysterious build issue, setting up a new development environment, or just satisfying your curiosity about what's installed on your machine, these commands will quickly give you the information you need.
Remember that having multiple versions installed is normal and often necessary, especially if you're maintaining applications that target different .NET versions. The key is understanding what you have available and how to use that information effectively in your development workflow.
Top comments (0)