How to Check if .NET (Core / 5+) Runtime is Installed in Batch Script
Modern versions of .NET (starting with .NET Core 1.x and continuing through .NET 5, 6, 7, and 8) have moved away from the monolithic registry-based installation of the legacy .NET Framework. Instead, modern .NET runtimes are modular and can be installed side-by-side or as portable "Self-contained" bundles. For developers and system administrators, verifying that the correct modern runtime is present on a machine is vital for running cross-platform web apps, microservices, and modern CLI tools. This guide explains how to use the dotnet command to identify installed runtimes from a Batch script.
Why Identify Modern .NET Versions?
- Modular Support: Ensuring the specific runtime (e.g., "ASP.NET Core" vs. "Desktop Runtime") is present.
- Side-by-Side Management: Identifying which versions are available to ensure the target application can find a compatible host.
- Environment Automation: Identifying if a machine needs the "Hosting Bundle" or just the basic runtime for a specific task.
- Runtime: Base libraries for console apps.
- Desktop Runtime: Adds libraries for Windows Forms and WPF apps.
- ASP.NET Core Runtime: Adds libraries for web-based server apps.
Method 1: Using dotnet --list-runtimes (Best Practice)
The dotnet executable is the primary interface for managing modern .NET versions. The --list-runtimes flag provides a comprehensive list of every version and flavor installed on the machine.
@echo off
echo [PROCESS] Retrieving installed .NET runtimes...
:: Search for the dotnet binary
where dotnet >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] .NET ^(Modern^) is NOT installed.
echo [HELP] Download from: https://dotnet.microsoft.com/download
) else (
echo [SUCCESS] .NET is installed. Listing runtimes:
echo.
dotnet --list-runtimes
)
pause
Method 2: Searching for a Specific Version
If your application requires a specific version (e.g., .NET 8.0), you can parse the list to look for a match.
@echo off
setlocal
set "TARGET_DOTNET=Microsoft.NETCore.App 8.0"
echo [PROCESS] Checking for %TARGET_DOTNET%...
:: First verify dotnet exists
where dotnet >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] .NET is not installed.
echo [HELP] Download from: https://dotnet.microsoft.com/download
pause
exit /b 1
)
dotnet --list-runtimes 2>nul | findstr /c:"%TARGET_DOTNET%" >nul
if %errorlevel% equ 0 (
echo [SUCCESS] Required .NET runtime is present:
dotnet --list-runtimes 2>nul | findstr /c:"%TARGET_DOTNET%"
) else (
echo [WARNING] .NET 8.0 Runtime was NOT found.
echo [HELP] Download from: https://dotnet.microsoft.com/download/dotnet/8.0
)
pause
Creating a Deployment Guard for Modern Apps
This script checks for both the dotnet binary and the specific "Desktop" runtime often required by Windows GUI apps.
@echo off
setlocal EnableDelayedExpansion
echo ============================================================
echo .NET (Modern) Readiness Auditor
echo ============================================================
echo.
echo Computer: %COMPUTERNAME%
echo Date: %date% %time%
echo.
echo ============================================================
echo.
:: ============================================================
:: Check 1: .NET CLI Availability
:: ============================================================
echo [1/4] Checking .NET CLI installation...
echo.
where dotnet >nul 2>&1
if !errorlevel! neq 0 (
echo ============================================================
echo CRITICAL: .NET NOT INSTALLED
echo ============================================================
echo.
echo [CRITICAL] .NET is not installed on this machine
echo.
echo The 'dotnet' command is not available in the system PATH.
echo.
echo What this means:
echo - .NET Core / .NET 5+ is not installed
echo - Modern .NET applications cannot run
echo - Development tools will not work
echo.
echo Action Required:
echo Download and install .NET from:
echo https://dotnet.microsoft.com/download
echo.
echo Recommended Downloads:
echo - For running apps: .NET Runtime
echo - For development: .NET SDK
echo.
pause
exit /b 1
)
echo [OK] .NET CLI is installed
echo.
:: Get dotnet location
for /f "delims=" %%p in ('where dotnet 2^>nul') do (
echo Location: %%p
goto :CliFound
)
:CliFound
echo.
:: Get .NET version
echo Version Information:
dotnet --version 2>nul
echo.
:: ============================================================
:: Check 2: Desktop Runtime (Windows GUI Apps)
:: ============================================================
echo ============================================================
echo [2/4] Checking Desktop Runtime
echo ============================================================
echo.
echo Required for: Windows Desktop applications (WPF, WinForms^)
echo.
set "DesktopFound=0"
set "DesktopVersions="
for /f "tokens=*" %%r in (
'dotnet --list-runtimes 2^>nul ^| findstr /C:"Microsoft.WindowsDesktop.App"'
) do (
set "DesktopFound=1"
echo [OK] %%r
:: Extract version for summary
if not defined DesktopVersions (
for /f "tokens=2" %%v in ("%%r") do set "DesktopVersions=%%v"
)
)
echo.
if !DesktopFound! equ 0 (
echo [WARNING] Desktop Runtime NOT FOUND
echo.
echo Impact:
echo - Windows desktop applications (WPF/WinForms^) will FAIL to launch
echo - Error: "You must install .NET Desktop Runtime"
echo.
echo Action Required:
echo Download Desktop Runtime from:
echo https://dotnet.microsoft.com/download/dotnet/runtime
echo.
echo NOTE: Choose "Desktop Runtime" not just "Runtime"
echo.
set "MissingComponents=Desktop"
) else (
echo [OK] Desktop Runtime is available
echo.
)
:: ============================================================
:: Check 3: ASP.NET Core Runtime (Web Apps)
:: ============================================================
echo ============================================================
echo [3/4] Checking ASP.NET Core Runtime
echo ============================================================
echo.
echo Required for: Web applications, APIs, Blazor apps
echo.
set "AspNetFound=0"
set "AspNetVersions="
for /f "tokens=*" %%r in (
'dotnet --list-runtimes 2^>nul ^| findstr /C:"Microsoft.AspNetCore.App"'
) do (
set "AspNetFound=1"
echo [OK] %%r
:: Extract version
if not defined AspNetVersions (
for /f "tokens=2" %%v in ("%%r") do set "AspNetVersions=%%v"
)
)
echo.
if !AspNetFound! equ 0 (
echo [INFO] ASP.NET Core Runtime NOT FOUND
echo.
echo Impact:
echo - Web applications and APIs will not run
echo - Only required if hosting web apps
echo.
echo If needed, download from:
echo https://dotnet.microsoft.com/download/dotnet/runtime
echo.
set "MissingComponents=!MissingComponents! AspNetCore"
) else (
echo [OK] ASP.NET Core Runtime is available
echo.
)
:: ============================================================
:: Check 4: Base Runtime
:: ============================================================
echo ============================================================
echo [4/4] Checking Base .NET Runtime
echo ============================================================
echo.
echo Required for: Console apps, class libraries
echo.
set "BaseFound=0"
for /f "tokens=*" %%r in (
'dotnet --list-runtimes 2^>nul ^| findstr /C:"Microsoft.NETCore.App"'
) do (
set "BaseFound=1"
echo [OK] %%r
)
echo.
if !BaseFound! equ 0 (
echo [WARNING] Base Runtime NOT FOUND
echo.
echo This is unusual if dotnet CLI exists.
echo.
) else (
echo [OK] Base Runtime is available
echo.
)
:: ============================================================
:: Full Runtime List
:: ============================================================
echo ============================================================
echo Complete Runtime Inventory
echo ============================================================
echo.
dotnet --list-runtimes 2>nul
if !errorlevel! neq 0 (
echo [ERROR] Could not list runtimes
)
echo.
:: ============================================================
:: SDK Check
:: ============================================================
echo ============================================================
echo SDK Status (for development^)
echo ============================================================
echo.
dotnet --list-sdks 2>nul | findstr /R "^" >nul
if !errorlevel! equ 0 (
echo Installed SDKs:
dotnet --list-sdks 2>nul
echo.
echo [OK] SDK is installed - development enabled
) else (
echo [INFO] No SDK installed
echo.
echo Impact:
echo - Cannot build or develop .NET applications
echo - Only runtime is available (apps can run^)
echo.
echo If development is needed:
echo https://dotnet.microsoft.com/download
)
echo.
:: ============================================================
:: Summary and Assessment
:: ============================================================
echo ============================================================
echo Readiness Assessment
echo ============================================================
echo.
set "ReadinessScore=0"
set "MaxScore=0"
:: Score calculation
set /a MaxScore+=1
if !DesktopFound! equ 1 set /a ReadinessScore+=1
set /a MaxScore+=1
if !BaseFound! equ 1 set /a ReadinessScore+=1
echo Component Status:
echo.
if !DesktopFound! equ 1 (
echo [ok] Desktop Runtime: Installed
) else (
echo [ ] Desktop Runtime: MISSING
)
if !AspNetFound! equ 1 (
echo [ok] ASP.NET Core: Installed
) else (
echo [ ] ASP.NET Core: Not installed (optional^)
)
if !BaseFound! equ 1 (
echo [ok] Base Runtime: Installed
) else (
echo [ ] Base Runtime: MISSING
)
echo.
echo Readiness Score: !ReadinessScore! / !MaxScore!
echo.
if !ReadinessScore! equ !MaxScore! (
echo ============================================================
echo RESULT: FULLY READY
echo ============================================================
echo.
echo [OK] System is ready for .NET desktop applications
echo.
set "ExitCode=0"
) else if !DesktopFound! equ 1 (
echo ============================================================
echo RESULT: READY ^(Partial^)
echo ============================================================
echo.
echo [OK] Desktop applications can run
echo [INFO] Some optional components missing
echo.
set "ExitCode=0"
) else (
echo ============================================================
echo RESULT: NOT READY
echo ============================================================
echo.
echo [CRITICAL] Missing required components
echo.
echo Missing: !MissingComponents!
echo.
echo Action Required:
echo Install missing runtimes from:
echo https://dotnet.microsoft.com/download/dotnet/runtime
echo.
set "ExitCode=1"
)
echo ============================================================
echo.
pause
endlocal
exit /b %ExitCode%
Common Pitfalls and How to Avoid Them
Folder Hunting
Technically, modern .NET runtimes are stored in C:\Program Files\dotnet\shared.
Wrong Way:
if exist "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.0" ...
:: This is unreliable because minor version updates (like 8.0.1) will change the path.
Correct Way:
Always use the dotnet --list-runtimes command. It is version-agnostic and will report all patches and release candidates correctly.
Self-Contained Apps
Some modern .NET apps are published as "Self-contained." They carry their own runtime within their folder.
If you are distributing an app, consider making it "Self-contained." This removes the need for your Batch script to check for a system-wide .NET installation, as all dependencies are bundled in the .exe.
Best Practices for Runtime Management
- Check for SDK: If your script is for a build server, use
dotnet --list-sdksinstead, as the SDK is required for compiling, while the "Runtime" is only for execution. - Verify Architecture: Modern .NET can be installed as x64 or ARM64. Use
dotnet --infoto get detailed architecture data. - Automatic Installers: For corporate rollouts, use the "dotnet-install" scripts (PowerShell-based) that Microsoft provides to install runtimes without needing user interaction.
Microsoft provides a fast "Rapid Release" cycle for .NET (roughly one version per year). Use your auditing script to identify machines running "Out-of-Support" versions (like .NET 5 or 7) and encourage an upgrade to Long Term Support (LTS) versions like .NET 6 or 8.
Conclusion
Querying for modern .NET runtimes via Batch script is an essential requirement for managing the next generation of Windows, Linux, and Cloud applications. By utilizing the dotnet CLI to list and verify specific runtime flavors, you can ensure that your software always has the foundation it needs to thrive. This professional approach to environment verification reduces support latency and ensures that your modern, high-performance applications run flawlessly on a verified and secure .NET platform.