Add .NET Framework Folder to PATH via batch file

When compiling a .NET application you often use the command line tools csc or vbc to compile the code to a dll file. However, the path environment variable does not always contain it (if all you have done is install the framework, or use SharpDevelop). Here is a way to add the folder to the path via a batch file. It does not add it twice if you have already added it to the path (i.e. it checks the path before adding).

Don't run directly, rather place it somewhere that is already in the path (e.g. c:\windows\system32), and do Start > Run > cmd /k DotNetSetPath[1.0|1.1|2.0]

"DotNetSetPath 1.0" for v1.0 of the framework, "DotNetSetPath 1.1" for v1.1, "DotNetSetPath 2.0" or "DotNetSetPath" for v2.0

Update (13 Feb, 2006): .NET 2.0 is now an option

DotNetSetPath.cmd

@echo off
rem v1.0.3705 is .NET 1.0, v1.1.4322 is .NET 1.1, v2.0.50727 is .NET 2.0
if "%1"=="2.0" goto dotnet20
if "%1"=="1.1" goto dotnet11
if "%1"=="1.0" goto dotnet10
:dotnet20
set dotnetver=v2.0.50727
goto checkpath
:dotnet11
set dotnetver=v1.1.4322
goto checkpath
:dotnet10
set dotnetver=v1.0.3705
:checkpath
rem check if framework path has been set.
echo %path% | find /I "%windir%\Microsoft.NET\Framework\%dotnetver%" > nul
rem if not contained in path then set
if errorlevel 1 goto setpath
echo .NET %dotnetver% framework folder already in path
goto end
:setpath
set path=%windir%\Microsoft.NET\Framework\%dotnetver%;%path%
echo .NET %dotnetver% framework folder added to path
:end

For another useful batch file for working with .NET check out .NET Command Prompt


Tags: ,

Comments

Popular posts from this blog

Link: HTML Agility Pack (.NET)

Basic Excel Spreadsheet Generation (ASP/ASP.NET)

ASP.NET: Binding alphabet to dropdown list