5

I have created a compile.bat and run.bat files, but when I double click on them they run on the Windows cmd prompt instead of the VS cmd prompt.

This is what I have in my compile.bat file:

devenv FileMgr.sln /rebuild debug
pause

The Windows cmd says "'devenv is not recognized as an internal or external command, operable program or batch file."

jbisa
  • 141
  • 1
  • 2
  • 11

4 Answers4

9

If I recall correctly, all the Visual Studio Command Prompt is is a batch script itself that initializes paths and environment variables. So if you simply call that batch script at the top of yours, you'll have all those settings for your script.

According to this question, MSVC 2008 has that batch file here:

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

It may not be in exactly the same place, but it should be something similar on your machine.

Community
  • 1
  • 1
Tyler Gill
  • 861
  • 6
  • 9
  • I would, but I need to be at 15 reputation. Also, for some reason it is not compiling from the .bat file anymore. Now I'm getting the following error: Cannot determine the location of the VS Common TOols folder. 'devenv' is not recognized as an internal or external command, operable program or batch file. It did work once, not sure why it isn't now. – jbisa Feb 11 '12 at 06:44
  • Ok, no problem then. As far as that VS Common Tools folder error, it looks like that error means the environment variable VS100COMNTOOLS (where 100 means 10.0, and matches the version of MSVC you want to use) either didn't exist, or was set to "". It also looks like this variable isn't set by the vcvarsall.bat script, but is registered with Windows when MSVC is installed. Can you check your environment variables in a fresh (non-VS) command prompt and see if that one got deleted? It should be something like this: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\ – Tyler Gill Feb 11 '12 at 16:09
2

you need devenv.exe to be present at location where your compile.bat is running. Please look at solution given here-

Simply type devenv.exe from the command line. If you get a message like this, then you do not have devenv.exe in your path. >>> 'devenv.exe' is not recognized as an internal or external command, operable program or batch file. >>> To fix this simply run the batch file, vsvars32.bat that comes with Visual Studio.NET from the command line in the working folder. After you run this batch file devenv.exe will be available from the command line in that folder.

http://windowsclient.net/blogs/faqs/archive/2006/05/26/how-do-i-start-visual-studio-from-the-command-line.aspx

I would usually copy the devenv.exe manually to the location where my bat file is kept.

DotNetUser
  • 6,494
  • 1
  • 25
  • 27
1

The VS cmd prompt sets some additional environment variables and adds data to existing (eg the PATH variable). You might consider adding the path of devenv to you normal path.

Sascha
  • 10,231
  • 4
  • 41
  • 65
  • Ok, so should I go to System Properties -> Advanced -> Environment Variables and then change the "Path" variable to the devenv path? – jbisa Feb 11 '12 at 05:54
  • 1
    Add it to the path, don't overwrite! If you overwrite, you'll probably have severe problems afterwards. The solution from Tyler Gill is another way without changing your system properties – Sascha Feb 11 '12 at 05:57
0

You may specify full path of devenv.exe:

C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE\devenv.exe FileMgr.sln /rebuild debug

But your batch file won't be portable to other machines/IDEs.

Ajay
  • 18,086
  • 12
  • 59
  • 105
  • I ran this on the compile.bat file once, and now every time I run compile.bat (even with the top line out of the file), VS opens my FileMgr solution. Is there any way I can have the compilation occur in the cmd window without having a new solution open? – jbisa Feb 11 '12 at 07:34