5

If you double click on a .bat file, windows will run it in a command prompt.

I want a specific .bat file to be launched using the .Net command prompt as it uses gacutil.

How can I achieve this?

thanks!

ozz
  • 5,098
  • 1
  • 50
  • 73
  • 1
    Any reason you can't use the full path to `gacutil`? – Oded Nov 16 '11 at 11:42
  • possible duplicate of [How can I call a batch file(.bat) in c#?](http://stackoverflow.com/questions/2996777/how-can-i-call-a-batch-file-bat-in-c) – Davide Piras Nov 16 '11 at 11:43
  • 3
    Not a duplicate. He isn't asking how to launch a batch file from C#. He wants to have the environment variables from the VS command prompt available to the batch file. – Oded Nov 16 '11 at 11:44

2 Answers2

2

If you put this line at the top of your bat file, it will set the environment variables for the visual studio command prompt

"C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"

You may need to adjust for your version of VS and if you're on a 64bit machine.

Ray
  • 45,695
  • 27
  • 126
  • 169
  • Don't you need Call at the start of that line? Also, best to look at the properties of the shortcut to the existing Visual Studio command prompt. For example, my shortcuts have an parameter (eg x86) – sgmoore Nov 16 '11 at 11:54
  • @sgmoore it seems to work fine without `call`. And you're right, `%programfiles%` is probably better. But then if you're just running it on your machine it doesn't matter. – Ray Nov 16 '11 at 12:01
1

The compilers can be used from command line (or makefiles) just like any other compilers. The main things you need to take care of are the INCLUDE and LIB environment variables, and PATH. If you're running from cmd.exe, you can just run this .bat to set the environment:

C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat

follow these links for more information: Using Visual Studio's 'cl' from a normal command line

How to create a Batch File for Visual Studio Command Prompt

Community
  • 1
  • 1
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75