Thursday, July 5, 2007

Visual Studio Building From the Command Line and Vim

There is a tool called devenv that lets you build visual studio solution files from the command line. (nmake also exists, but you can't use the solution files).

To get yourself access, you need to setup the environment. I have a batch file that I launch a command prompt with that gives me the basic environment I need.

@set PATH=%HOMEDRIVE%%HOMEPATH%\xxx;c:\Program Files\Vim\vim71;%PATH%
@%comspec% /k ""C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat"" x86

You can make a shortcut to cmd.exe with the flags
\k c:\path\to\the.bat
which first runs the script and then gives you the command prompt.

Next I made a build.bat file in the base of my source code, one level above where the sln file is:

devenv ../TheProject.sln /Build Debug


Next I created a vim compiler file which I placed in c:\program files\vim\vimfiles\compiler\devenv.vim:

" Vim compiler file
" Compiler: ms sln
" Last Change: 2007 July 05

if exists("current_compiler")
finish
endif
let current_compiler = "mssln"

if exists(":CompilerSet") != 2
command -nargs = CompilerSet setlocal
endif

" Default errorformat
CompilerSet errorformat=1>%f(%l)\ :\ error\ %t%n:\ %m,
\1>%f(%l)\ :\ fatal\ error\ %t%n:\ %m,

" Hack to build.bat
CompilerSet makeprg=build.bat


Now, if you launch gvim from the root of the source, you can run :make and :cnext/:cprev through the errors.

It's a little hacky, and you still need to go through the actual IDE to add files to the project. There may well be a less hacky was to do this.

0 comments: