I use cygwin extensively and hate switching over to Visual Studio Command Prompt just to be able to use msbuild. I figured out how I can invoke msbuild from cygwin. It’s a neat and easy solution, but I am sure a better solution exists.
Steps to follow:
1. Create a file called vs [See Note 1]
2. Copy and paste the following line in the file:
cmd /k “C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat” x86
3. Save the file under /usr/bin. [See Note 2]
4. Make sure the file is executable. Execute the command
chmod +x vs
You are done.
Test it:
1. Open up cygwin and execute the file.
cygwin> vs
It will display this message and give you a VS command prompt:
Setting environment for using Microsoft Visual Studio 2005 x86 tools
Note 1: You can use a different name for the file. I named it vs for visual studio.
Note 2: You can put it under any directory you like. If you decide to put it under any other directory, then you you have two options:
1. Add that directory to PATH. OR
2. Give the full path to the directory whenever you execute this file.
Note 3: For some reason the UP key does not work. I need to find a fix for this.
Note 4: I know a better solution exists. The batch file which I execute in the vs file is setting a few environment variables. Instead of invoking this batch file, I should set the environment variables directly. This is a neater solution.
If you launch cygwin using a shortcut to cygwin.bat, you can add the following to cygwin.bat:
call “C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat” x86
Another approach is to save the following in a file, say vs2005, and source it from your .bashrc. You can then use msbuild even when you logged in through ssh.
$ cat ~/.bash/vs2005
# translate
# ‘C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat’
# into bash commands
msdev=’C:\Program Files\Microsoft Visual Studio 8′
export VSINSTALLDIR=$msdev
export VCINSTALLDIR=$msdev\\VC
export FrameworkDir=’C:\WINDOWS\Microsoft.NET\Framework’
export FrameworkVersion=v2.0.50727
export FrameworkSDKDir=$msdev\\SDK\\v2.0
# Root of Visual Studio IDE installed files.
export DevEnvDir=$msdev\\Common7\\IDE
VCINSTALLDIR_UNIX=$(cygpath –unix “$VCINSTALLDIR”)
DevEnvDir_UNIX=$(cygpath –unix “$DevEnvDir”)
FrameworkDir_UNIX=$(cygpath –unix “$FrameworkDir”)
FrameworkSDKDir_UNIX=$(cygpath –unix “$FrameworkSDKDir”)
TOOLSDIR_UNIX=$(cygpath –unix “$msdev\\Common7\\Tools”)
export PATH=$DevEnvDir_UNIX:$VCINSTALLDIR_UNIX/bin:$TOOLSDIR_UNIX:$TOOLSDIR_UNIX/Bin:$VCINSTALLDIR_UNIX/PlatformSDK/Bin:$FrameworkDir_UNIX/$FrameworkVersion:$VCINSTALLDIR_UNIX/VCPackages:$PATH
export INCLUDE=$VCINSTALLDIR\\ATLMFC\\INCLUDE’;’$VCINSTALLDIR\\INCLUDE’;’$VCINSTALLDIR\\PlatformSDK\\include’;’$FrameworkSDKDir\\include
export LIB=$VCINSTALLDIR\\ATLMFC\\LIB’;’$VCINSTALLDIR\\LIB’;’$VCINSTALLDIR\\PlatformSDK\\lib’;’$FrameworkSDKDir\\lib
export LIBPATH=$FrameworkDir\\$FrameworkVersion’;’$VCINSTALLDIR\\ATLMFC\\LIB
unset msdev
unset VCINSTALLDIR_UNIX
unset DevEnvDir_UNIX
unset FrameworkDir_UNIX
unset FrameworkSDKDir_UNIX
unset TOOLSDIR_UNIX
$ cat ~/.bashrc
if [ -n “$PS1” ]; then
# source MS VS 2005 settings
source ~/.bash/vs2005
# snipped rest of the file
fi
HTH,
Mangesh
Forgot to credit Mark Hadfield (see http://cygwin.com/ml/cygwin/2005-07/msg00849.html)
Thanks for the much neater solution, Mangesh.