4

If I need to use microsoft C# compiler from the normal command prompt, it says right here how and it says right here how I set the environment variable (by running VSVARS32.BAT). I execute it and after that I can run "csc" (the compiler). However the effect seems to disappear when I close the command line window that run VSVARS32.BAT

Is there a way to make the environment variables permanent, so that I can run csc.exe from an application?

Louis Rhys
  • 34,517
  • 56
  • 153
  • 221
  • I'm a little confused by your setup as described above. If I read it correctly, you open one command prompt which you use to run VSVARS32.bat. Does this open another command prompt (with the env variables defined) or does it just load them in the current command prompt? For the former, closing the original command prompt should not affect the new window. If it's the latter, then you're out of luck - you'll have to re-open and run VCVARS32.bat everytime you open the command prompt. Unless of course, you take one of the approaches mentioned below... – cristobalito Jul 17 '10 at 15:46
  • it's the latter.. the problem is I am calling csc.exe from another program and I can't make it to call the bat file first – Louis Rhys Jul 17 '10 at 15:55

4 Answers4

4

I would suggest that you create a new .bat file that launches the vcvars.bat and then your application. This will make sure that the environment is setup appropriately.

Mike
  • 3,462
  • 22
  • 25
  • `SET current_folder=%CD% DIR /S /B *.sln | FINDSTR /e .sln > project-files.list ------------------------------------------------------------------------- CALL "%VS100COMNTOOLS%\vsvars32.bat" FOR /F "TOKENS=*" %%a IN ('TYPE project-files.list') DO ( CD %%~dpa devenv "%%a" /build "Debug" devenv "%%a" /build "Release" -------------------------------------------------------------------- )` , this is a portion of my script, executing from norml CMD. After the for loop - i want to revert the `PATH` variable by removing all the changes by vcvars32.bat, any solution? – Banee Ishaque K Jul 28 '17 at 20:12
  • Check this please, https://gist.github.com/Baneeishaque/0da7d54af47fab0d2f2509a5825da092 – Banee Ishaque K Jul 28 '17 at 20:22
1

The VSVAR32.bat file just modifies some environment variables (appends a directory to path, sets LIB and INCLUDE, etc.). You can always make the same changes to the main Windows envirnonment so they are inherited by all subsequent processes (from the control panel "system" applet).

Quite a few other development tools use the same environment variables (including earlier Visual Studio versions). Making the configuration changes in the main environment is not so convenient when you want to use development tools that require conflicting settings on the same PC (that's why Microsoft puts them in MSVAR32.bat instead of modifying the main environment). , so it is useful to only apply these settings when they are required, as they conflict by the settings required by other development tools. Putting these changes in the main environment casues problems if you want to use different developmemnt tools on the same PC.

The other possibility to to have your application that will invoke csc.exe modify the enviroment it passes to the child process in the same manner as MSVAR32.bat.

Stephen C. Steel
  • 4,380
  • 1
  • 20
  • 21
0

Try to add the command to run it in the autoexec.NT file in windows directory.

laurent
  • 888
  • 8
  • 13
  • it runs each time you start the command prompt. Open autoexec.nt (in windows directory) and edit it to add the command you would type on the keyboard to run the .bat – laurent Jul 18 '10 at 00:49
  • continuation: You can put the content of the VSVARS32.bat in the autoexec.NT or add c:\path_to_\VSVARS32.bat at the end of autoexec.nt. autoexec.nt is in system32 directory - I can't remember now and I can't test it as my machine is not windows since some time but I think you need to use `command.com` instead of `cmd.exe` for autoexec.nt to be used. – laurent Jul 18 '10 at 01:25
0

Like laurent-rpnet says, you can call it in your autoexec.nt file. Alternately, you can add the environmental variables that it sets to the list in Control Panel | System | Advanced | Environment Variables.

Or you could create a make file and put them in there (or call the bat), and use the make file to build your project from the command line.

Marc Bernier
  • 2,928
  • 27
  • 45
  • again, what does autoexec.nt do, and how do i do it? the batch file has a lot of contents, including conditionals and other things that I don't completely understand, so I don't know what exactly I should add in control panel's environment variable – Louis Rhys Jul 17 '10 at 14:53
  • autoexec runs as soon as you log on. So, any variables you set there will be available throughout the duration of your session. – Agnel Kurian Jul 17 '10 at 14:59
  • oh how do I add it to autoexec? – Louis Rhys Jul 17 '10 at 15:43